Java Reference
In-Depth Information
FIGURE 10.7
An input dialog
box.
The input dialog box method call returns a string that represents the user's response. The
following statement creates the input dialog box shown in Figure 10.7:
String response = JOptionPane.showInputDialog(null,
“Enter your name:”);
You also can create an input dialog box with the showInputDialog( Component ,
Object , String , int ) method. The first two arguments are the same as the shorter
method call, and the last two are the following:
The title to display in the dialog box title bar
n
One of five class constants describing the type of dialog box: ERROR_MESSAGE ,
INFORMATION_MESSAGE , PLAIN_MESSAGE , QUESTION_MESSAGE , or WARNING_MESSAGE
n
The following statement uses this method to create an input dialog box:
String response = JOptionPane.showInputDialog(null,
“What is your ZIP code?”,
“Enter ZIP Code”,
JOptionPane.QUESTION_MESSAGE);
Message Dialog Boxes
A message dialog box is a simple window that displays information, as shown in Figure
10.8.
FIGURE 10.8
A message dialog
box.
A message dialog box can be created with a call to the showMessageDialog( Component ,
Object ) method. As with other dialog boxes, the arguments are the parent component
and the string, component, or icon to display.
Search WWH ::




Custom Search