// // "closeable frame" class, alternate implementation. compare with // CloseableFrame.java. // import java.awt.* ; import java.awt.event.* ; // // a CloseableFrameAlt 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 CloseableFrameAlt extends Frame { static int framecount = 0 ; // zero-argument constructor for frame without title. public CloseableFrameAlt() { super() ; subConstruct() ; } // one-argument constructor for frame with title. public CloseableFrameAlt(String s) { super(s) ; subConstruct() ; } void subConstruct() { framecount++ ; // respond to window-close event and ignore other // window events. addWindowListener(new WindowAdapter() { // WindowAdapter defines "stub" methods for // all WindowListener methods. public void windowClosing(WindowEvent wEvt) { // get rid of frame and release // associated resources. dispose() ; framecount-- ; if (framecount <= 0) System.exit(0) ; } } ) ; } }