import java.awt.*; import java.awt.event.*; /** * Makes use of an "anonymous" inner class to listen to the WindowClosing event. */ public class SimpleGUI { private Frame _frame; // The frame for the GUI. public SimpleGUI() { _frame = new Frame("Simple GUI"); //Standard way to free system's resources for Window class when closing. _frame.addWindowListener (new CloseWindowListener()); _frame.setSize (240, 300); _frame.setVisible (true); } /** * Standard way to free system's resources for Window class when closing. */ class CloseWindowListener extends WindowAdapter { public void windowClosing(WindowEvent e) { _frame.dispose (); //frees system's resources. System.exit(0); } } /*** * Entry point into the program * @param args The parameters for the entry. They are not used here. */ public static void main(String[] args) { new SimpleGUI(); } }