Java tutorial
import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; public class CloseFrameAction extends JFrame { public CloseFrameAction() { setTitle("CloseableFrame"); setSize(300, 200); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public static void main(String[] args) { JFrame frame = new CloseFrameAction(); frame.show(); } }