Java Reference
In-Depth Information
17.5.1
Class JOptionPane
Class
JOptionPane
, in package
javax.swing
, provides several static methods
for creating and showing different kinds of dialog windows. We look at four of
the methods here:
showMessageDialog
,
showInputDialog
,
showConfirmDia-
log
, and
showOptionDialog
.
Method showMessageDialog
Execution of the method call shown below causes the dialog window on the
left of Fig. 17.18 to appear on your monitor:
Activity
17-5.1
JOptionPane.showMessageDialog(
null
,
"Division by 0",
"arithmetic error",
JOptionPane.ERROR_MESSAGE);
The call has four arguments. The first argument, the
parent window
, is explained
later. The second is the
message
of the dialog window. The third is the
title
of the
dialog window. The fourth determines the way the dialog window looks.
There are four other possibilities for the fourth argument:
•
JOptionPane.
INFORMATION_MESSAGE
•
JOptionPane.
WARNING_MESSAGE
•
JOptionPane.
QUESTION_MESSAGE
•
JOptionPane.
PLAIN_MESSAGE
Figure 17.18:
JOptionPanes
Figure 17.19:
A
showInputDialog
window and a
showConfirmDialog
window
Search WWH ::
Custom Search