import java.awt.*; import javax.swing.*; import java.awt.event.*; public class CloseWindow implements WindowListener { public CloseWindow () { JFrame frame = new JFrame("Event Test"); Container content = frame.getContentPane(); content.setLayout(new FlowLayout()); frame.setSize(300,300); frame.addWindowListener(this); frame.setVisible(true); } public void windowClosing(WindowEvent we) { System.exit(0); } public void windowActivated(WindowEvent we) {} public void windowClosed(WindowEvent we) {} public void windowDeactivated(WindowEvent we) {} public void windowDeiconified(WindowEvent we) {} public void windowIconified(WindowEvent we) {} public void windowOpened(WindowEvent we) {} public static void main(String[] args) { new CloseWindow(); } }