import java.awt.*; import java.awt.event.*; import javax.swing.*; class TestFrameListener { public static void main(String[] args){ Frame frame = new Frame(); frame.setTitle("My first JFrame!"); /* Without show() the frame will not appear on screen! */ frame.setSize(200,400); frame.show(); frame.addWindowListener(new myWindowListener()); } } class myWindowListener extends WindowAdapter{ public void windowClosing(WindowEvent e){System.exit(0);} } /* Instead I could have used * class myWindowListener implements WindowListener{ * } */