JFrame.EXIT_ON_CLOSE
JFrame setDefaultCloseOperation Method can take different variables.JFrame.EXIT_ON_CLOSE is very popular especially when the programmer wants to exit the application when the close button is clicked.
JFrame.EXIT_ON_CLOSE Example
[
import javax.swing.JFrame; import javax.swing.JTextArea; import java.awt.Dimension; import java.awt.Point; public class JFrameExitOnCloseExample { public JFrame frame; public JTextArea area; JFrameExitOnCloseExample() { frame=new JFrame(); area=new JTextArea(200,200); area.setBounds(10,10,200,200); frame.add(area); frame.setLayout(null); //setting JFrame default close operation
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setting JFrame size
frame.setSize(new Dimension(300,300));
//setting JFrame location
frame.setLocation(new Point(300,300));
//making JFrame visible
frame.setVisible(true); } public static void main(String args[]) { new JFrameExitOnCloseExample(); } }]