Java Reference
In-Depth Information
Preventing the user from resizing the window
Generally, the user can use the resize control to change the size of the win-
dow. To prevent such resizing, use method call:
jf.setResizable( false );
The close button
The close button can have various behaviors. The default behavior is to hide
the window. Method call jf.setVisible( true ); makes it visible again. You
can change the action that is connected to the close button using the call:
jf.setDefaultCloseOperation( argument ) .
There are four possible values for the argument , all constants of class Window-
Constants . Each provides a different effect when the close button is pressed:
Argument
Action when pressing the button
Nothing.
DO_NOTHING_ON_CLOSE
Hide the window.
HIDE_ON_CLOSE
Dispose of the window.
DISPOSE_ON_CLOSE
Exit program by calling System.exit(0);
EXIT_ON_CLOSE
Using a subclass of JFrame
We can define subclass BasicFrame of JFrame , with a suitable constructor,
and place initializing statements in the constructor of the class. Other program-
mers using class BasicFrame will usually want to set the location themselves,
delay showing the window, or alter the contents of the window. Therefore, calls
to setVisible and setLocation are usually left to the user of the subclass.
public class BasicFrame extends JFrame {
/** Constructor: a non-visible instance with title t */
public BasicFrame(String t)
{ super (t); pack(); }
}
Figure 17.2:
JFrame with a BorderLayout
Search WWH ::




Custom Search