Java Reference
In-Depth Information
Unlike the other dialog boxes, message dialog boxes do not return any kind of response
value. The following statement creates the message dialog box shown in Figure 10.8:
JOptionPane.showMessageDialog(null,
“The program has been uninstalled.”);
You also can create a message input dialog box by calling the
showMessageDialog(
Component
,
Object
,
String
,
int
)
method. The use is identical
to the
showInputDialog()
method, with the same arguments, except that
showMessageDialog()
does not return a value.
The following statement creates a message dialog box using this method:
JOptionPane.showMessageDialog(null,
“An asteroid has destroyed the Earth.”,
“Asteroid Destruction Alert”,
JOptionPane.WARNING_MESSAGE);
10
Option Dialog Boxes
The most complex of the dialog boxes is the option dialog box, which combines the fea-
tures of all the other dialog boxes. It can be created with the
showOptionDialog(
Component
,
Object
,
String
,
int
,
int
,
Icon
,
Object[]
,
Object
)
method.
The arguments to this method are as follows:
The parent component of the dialog box
n
The text, icon, or component to display
n
A string to display in the title bar
n
The type of box, using the class constants
YES_NO_OPTION
or
YES_NO_CANCEL_
OPTION
, or the literal
0
if other buttons will be used instead
n
The icon to display, using the class constants
ERROR_MESSAGE
,
INFORMATION_
MESSAGE
,
PLAIN_MESSAGE
,
QUESTION_MESSAGE
, or
WARNING_MESSAGE
, or the literal
0
if none of these should be used
n
An
Icon
object to display instead of one of the icons in the preceding argument
n
An array of objects holding the objects that represent the choices in the dialog box,
if
YES_NO_OPTION
and
YES_NO_CANCEL_OPTION
are not being used
n
The object representing the default selection if
YES_NO_OPTION
and
YES_NO_CANCEL
option are not being used
n