Swing
Frames
Set the default close operation
The control menu for a frame
The setDefaultCloseOperation method of the JFrame class
| Method | Description |
|---|---|
| setDefaultCloseOperation(action) | Sets the default close action for the frame. |
Constants to set the default close operation
| Constant | Description |
|---|---|
| JFrame.EXIT_ON_CLOSE | Exits the application when the user closes the window. |
| WindowConstants.DO_NOTHING_ON_CLOSE | Provides no default action, so the program must explicitly handle the closing event. |
| WindowConstants.HIDE_ON_CLOSE | Hides the frame when the user closes the window. This is the default action. |
| WindowConstants.DISPOSE_ON_CLOSE | Hides and disposes of the frame when the user closes the window. |
A class that defines a closeable frame
class FutureValueFrame extends JFrame
{
public FutureValueFrame()
{
setTitle("Future Value Calculator");
setBounds(267, 200, 267, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}