// // "closeable frame" class. // import java.awt.* ; import java.awt.event.* ; // // a CloseableFrame object is a frame that listens for window events, // and processes "close" by disposing of the frame. // this class has a static counter variable that keeps track of the // number of frames created and not closed. when all have been // closed, System.exit() is called to terminate the application. // public class CloseableFrame extends Frame implements WindowListener { static int framecount = 0 ; // zero-argument constructor for frame without title. public CloseableFrame() { super() ; addWindowListener(this) ; framecount++ ; } // one-argument constructor for frame with title. public CloseableFrame(String s) { super(s) ; addWindowListener(this) ; framecount++ ; } // respond to window-close event. public void windowClosing(WindowEvent wEvt) { // get rid of frame and release associated resources. dispose() ; framecount-- ; if (framecount <= 0) System.exit(0) ; } // ignore other window events. public void windowClosed(WindowEvent wEvt) {} ; public void windowOpened(WindowEvent wEvt) {} ; public void windowIconified(WindowEvent wEvt) {} ; public void windowDeiconified(WindowEvent wEvt) {} ; public void windowActivated(WindowEvent wEvt) {} ; public void windowDeactivated(WindowEvent wEvt) {} ; }