Java Reference
In-Depth Information
Dial-a-Dialog Methods
Description
showMessageDialog
(Component parent,
Object message)
This method displays a modal dialog with the default title
"Message" . The first argument is the parent for the dialog. The
Frame object containing the component will be used to position
the dialog. If the first argument is null , a default Frame object
will be created and that will be used to position the dialog
centrally on the screen.
The second argument specifies what is to be displayed in addition
to the default OK button. This can be a String object specifying
the message or an Icon object defining an icon to be displayed. It
can also be a Component , in which case the component will be
displayed. If some other type of object is passed as the second
argument, its toString() method will be called, and the
String object that is returned will be displayed. You will usually
get a default icon for an information message along with your
message.
You can pass multiple items to be displayed by passing an array of
type Object[] for the second argument. Each array element will
be processed as above according to its type and they will be
arranged in a vertical stack. Clever, eh?
showMessageDialog
(Component parent,
Object message,
String title,
int messageType)
This displays a dialog as above, but with the title specified by the
third argument. The fourth argument, messageType , can be:
ERROR _ MESSAGE
INFORMATION _ MESSAGE
WARNING _ MESSAGE
QUESTION _ MESSAGE
PLAIN _ MESSAGE
These determine the style of the message constrained by the
current look and feel. This will usually include a default icon, such
as a question mark for QUESTION _ MESSAGE .
showMessageDialog
(Component parent,
Object message,
String title,
int messageType,
Icon icon)
This displays a dialog as above except that the icon will be what
you pass as the fifth argument. Specifying a null argument for the
icon will produce a dialog the same as the previous version of the
method.
We could have used one of these for the About dialog instead of all that messing about with inner
classes. Let's see how.
Try It Out - An Easy About Dialog
Delete the inner class, AboutDialog , from SketchFrame - we won't need that any longer. Change
the implementation of the actionPerformed() method in the SketchFrame class to:
Search WWH ::




Custom Search