Java Reference
In-Depth Information
Dialog Windows
A dialog window is used to interact with the user, either to share information with the user
or obtain information from the user. The java.awt.Dialog class represents an AWT dialog
window, and the javax.swing.JDialog class represents a Swing dialog window. Note that the
JDialog class extends the Dialog class.
A dialog window is either modal or modeless. A modal dialog window must be closed
before the program can continue. A modeless dialog window is one that does not need to be
closed, and you still can interact with the program or programs behind the modeless dialog.
A dialog window often has an owner window that is either another dialog window or a
frame window. The owner of a dialog window is assigned by using one of the constructors
of the Dialog or JDialog classes:
public Dialog(Frame owner, String title, boolean modal). Creates a Dialog
with the given Frame as its owner. The String appears in the title bar, and if the
boolean is true, the Dialog will be modal.
public Dialog(Dialog owner, String title, boolean modal).
Creates a Dialog
with the given Dialog as its owner.
public JDialog(Frame owner, String title, boolean modal).
Creates a JDialog
with the given Frame as its owner.
public JDialog(Dialog owner, String title, boolean modal).
Creates a JDialog
with the given Dialog as its owner.
public JDialog().
Creates a JDialog with no owner or title. It will be modeless by
default.
There are other constructors in the Dialog and JDialog classes that contain a variation of
the parameters listed above.
After you have instantiated a dialog window, you invoke the show() method to activate
the dialog window and the hide() method to hide the dialog window. These methods are
defined as follows:
public void show(). This method makes the Dialog visible. If the Dialog is modal,
this method will not return until the hide() or dispose() method is invoked on this
Dialog object. If the Dialog is modeless, this method returns immediately.
public void hide(). This method hides the Dialog and causes the show() method
to return if the Dialog is modal.
Notice that the dispose() method can also be used to hide a Dialog window. (The dif-
ference between hide() and dispose() is that the dispose() method frees up any resources
involving the screen and other native devices. A disposed window can still be redisplayed
using the show() method.)
The following ModalDemo program creates a Dialog window with a Frame as its owner.
The dialog is modal, so when the dialog is displayed, it must be closed before the user can
interact with the Frame.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
Search WWH ::




Custom Search