Java examples for Swing:JFrame
You can set the JFrame default close behavior by using one of the four constants in its setDefaultCloseOperation() method.
// Exit the application when the JFrame is closed
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
The other options are:
Example.
import javax.swing.JFrame; public class Main { public static void main(String[] args) { // Create a frame JFrame frame = new JFrame("Revised Simplest Swing"); // Set the default close behavior to exit the application frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set the x, y, width and height properties in one go frame.setBounds(50, 50, 200, 200);//from w w w. j a v a2 s .c o m // Display the frame frame.setVisible(true); } }