import java.awt.*; import java.awt.event.*; /** * Handles java.awt.event.WindowEvent.WINDOW_CLOSING events on behalf * of a java.awt.Window. */ public class WindowClosingListener extends WindowAdapter { /** * The Window on behalf of whom these events are handled. */ private Window window; /** * Remember your window; * @param w The window to be remembered/closed. */ public WindowClosingListener( Window w ) { this.window = w; } /** * Handle WINDOW_CLOSING events by closing the window and exiting. */ public void windowClosing(WindowEvent evt) { System.out.print("Handling closing.."); this.window.dispose(); System.out.println("..done. Exiting...."); System.exit(0); } }