Java Reference
In-Depth Information
location of the frame and also ensures proper termination as explained above. We
now list the program and explain it in detail.
File: its/SimpleFrame/SimpleFrame.java
1. package its.SimpleFrame;
2.
3. import javax.swing.JFrame;
4.
5. public class SimpleFrame extends JFrame
6. {
7.
public SimpleFrame()
8.
{
9.
this .setSize(200,200);
10.
this .setLocation(200,200);
11.
this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
12.
}
13.
14.
// Makes the frame visible.
15.
public void showIt(){
16.
this .setVisible( true );
17.
}
18.
19. // Makes the frame visible and sets the title text.
20. public void showIt(String title){
21.
this .setTitle(title);
22.
this .setVisible( true );
23. }
24.
25. // Makes the frame visible and sets the title text
26. // and the position of the window.
27.
28. public void showIt(String title, int x, int y){
29.
this .setTitle(title);
30.
this .setLocation(x,y);
31.
this .setVisible( true );
32. }
33.
34. // Makes the frame invisible.
35. public void hideIt(){
36.
this .setVisible( false );
37. }
38. }
Let us look at the code: the class SimpleFrame is defined in a package of its own
which is also called SimpleFrame .Itisasub-package of the its package. We have to
Search WWH ::




Custom Search