package CSLib; import java.awt.*; import java.awt.event.*; /** * ClosableDialog is a base class that obeys the * windowClosing event. It is extended by various * CSLib classes. It uses an inner class, * DialogCloser to implement the windowClosing listener, * with DialogCloser extending the WindowAdapter * class. *

* ClosableDialog should be compared with * ClosableFrame, which implements the * WindowListener methods individually. * * @see ClosableFrame * @see java.awt.event.WindowAdapter * @see java.awt.Dialog * * @author M. Dennis Mickunas */ public class ClosableDialog extends Dialog { /** * Constructs a non-modal dialog box in a new frame with a blank title; * this dialog box can respond to the "window closing" event. */ public ClosableDialog () { this (new Frame(), "", false); } /** * Constructs a dialog box in a new frame with a blank title and a * specified modality; this dialog box can respond to the * "window closing" event. * * @param modal the specified modality */ public ClosableDialog (boolean modal) { this (new Frame(), "", modal); } /** * Constructs a non-modal dialog box in a new frame with a specified * title; this dialog box can respond to the "window closing" event. * * @param title the string to use as this ClosableDialog title */ public ClosableDialog (String title) { this (new Frame(), title, false); } /** * Constructs a dialog box in a new frame with a specified title and * modality; this dialog box can respond to the "window closing" event. * * @param title the string to use as this ClosableDialog title * @param modal the specified modality */ public ClosableDialog (String title, boolean modal) { this (new Frame(), title, modal); } /** * Constructs a dialog box with a specified title and modality; * this dialog box can respond to the "window closing" event. * * @param home a Frame to parent this Dialog Box * @param title the string to use as this ClosableDialog title * @param modal the specified modality */ public ClosableDialog (Frame home, String title, boolean modal) { super(home, title, modal); addWindowListener(new DialogCloser()); } /** * DialogCloser is an inner class that implements the * windowClosing listener for ClosableDialog. It does this * by extending the Java convenience wrapper WindowAdapter. * * @see java.awt.event.WindowAdapter */ class DialogCloser extends WindowAdapter { /** * Cleans up the window, and terminates the program. * * @param e The specific WindowEvent that occurred. */ public void windowClosing (WindowEvent e) { dispose(); // System.exit(0); } } }