// COBOL Programmers Swing With Java - copyright 2005 Doke, Hardgrave, & Johnson // Chapter 11 - OO Development Issues // Program to demonstrate the creation and closing of a window // MyWindow.java 1 JAN 05 import java.awt.*; import java.awt.event.*; public class MyWindow extends Frame implements WindowListener { static MyWindow aWindow; // reference variable for window instance public static void main(String args[]) // main method called first { aWindow = new MyWindow(); // create instance & call constructor aWindow.setSize(300,150); // pixels wide x pixels high aWindow.setTitle("A Title for My Window"); // place title aWindow.show(); // display the window } // end of main public MyWindow () // constructor method { addWindowListener(this); // register as listener for window events } // end of constructor // note that aWindow is both a source object & a listener object // The following 7 methods are required because we implemented // the WindowListener interface // When a window event occurs, Java calls the appropriate handler // method below. windowClosing is the only one we have code for. public void windowClosing(WindowEvent event) { System.exit(0); // terminate this program } // end of windowClosing public void windowClosed(WindowEvent event) {} public void windowDeiconified(WindowEvent event) {} public void windowIconified(WindowEvent event) {} public void windowActivated(WindowEvent event) {} public void windowDeactivated(WindowEvent event) {} public void windowOpened(WindowEvent event) {} } // end of MyWindow.java