Java Reference
In-Depth Information
Table 3-12
JOptionPane show Methods
METHOD
PURPOSE
EXAMPLE
1. showInputDialog()
Prompts for input
JOptionPane.showInputDialog(null, “message”);
2. showMessageDialog()
Displays information to the
JOptionPane.showMessageDialog(null, “message”,
user
“title bar caption”, messageType);
3. showConfirmDialog()
Asks a confirming question,
JOptionPane.showConfirmDialog(null, “message”,
like yes/no/cancel
“title bar caption”, messageType);
In the first example shown in Table 3-11, the showInputDialog() method
displays a dialog box with a message and a text box for user input. The
showInputDialog() method actually is assigned to a String variable with an
assignment statement. Figure 3-30 shows a typical input dialog box that displays
when the JOptionPane.showInputDialog() method is used.
text box
title bar
message
icon
FIGURE 3-30
The second and third examples in Table 3-12 each use four method argu-
ments. The first argument indicates the placement of the dialog box on the
screen. The Java keyword, null, instructs the program to display the dialog box
centered within the program's active window. The second argument represents
the display area inside the dialog box and can be an object, icon, component, or
String. The third argument indicates the caption that appears on the title bar. The
fourth argument refers to one of various constants defined in the JOptionPane
class. A constant is a value that Java understands to have a certain, intrinsic
meaning. In the case of JOptionPane dialog boxes, the argument refers to one of
several styles of dialog boxes with displayed icons, as shown in Table 3-13 on the
next page.
 
Search WWH ::




Custom Search