Java Reference
In-Depth Information
Table 3-13
Constant Message Types
MESSAGE TYPE
DISPLAYED ICON
ERROR_MESSAGE
INFORMATION_MESSAGE
WARNING_MESSAGE
QUESTION_MESSAGE
PLAIN_MESSAGE
no icon display
JOptionPane dialog boxes can return a value. In the case of an input dialog
box (example 1 in Table 3-12 on the previous page), the returned value is the
data entered into the text box by the user. In example 2, a message box simply
displays a message and has no return value. In example 3, the return value is an
integer indicating the option selected by the user.
The following steps replace the readLine() methods with JOptionPane
showMessageDialog() and showInputDialog() methods, as shown in Table 3-14.
Table 3-14
Replacing Code to Create Swing Dialog Boxes
LINE
DELETE OLD CODE
REPLACE WITH NEW CODE
36
System.out.println(“\tYOUR
JOptionPane.showMessageDialog(null, “YOUR BODY
BODY MASS INDEX IS “ +
MASS INDEX IS “ + Math.round(index) +”.”, “Body Mass
Math.round(index) + “.”);
Calculator”,JOptionPane.PLAIN_MESSAGE);
26, 27
System.out.print(“\t\tEnter your
weight=JOptionPane.showInputDialog(null, ”Enter your
weight to the nearest pound: “);
weight to the nearest pound: “);
weight = dataIn.readLine();
23, 24
System.out.print(“\t\tEnter your
height=JOptionPane.showInputDialog(null, ”Enter your
height to the nearest inch: “);
height to the nearest inch: “);
height = dataIn.readLine();
 
Search WWH ::




Custom Search