Java Reference
In-Depth Information
Message: With a message pop-up, there's no return value. Therefore, the method is defined
void show[Internal]MessageDialog(...) .
Input: With an input pop-up, the return value is either what the user typed in a text field
(a String ) or what the user picked from a list of options (an Object ). Therefore, the
show[Internal]InputDialog(...) methods return either a String or Object , depending
on which version you use.
Confirm: With the confirm pop-up, the return value signifies which, if any, button the
user picked within the option pane. After a button is picked, the pop-up window is
dismissed, and the returned value is one of the integer constants shown in Table 9-1.
Therefore, the method here is defined as int show[Internal]ConfirmDialog(...) .
Option: With the option pop-up, the return value is an int , the same type as the confirm
pop-up, so the methods are defined int show[Internal]OptionDialog(...) . If the
button labels are manually specified with a non- null argument, the integer represents
the selected button position.
The information in Table 9-2 should help you understand the 25 methods and their argu-
ments. The method names (and return types) are found on the left side of the table, and their
argument lists (and data types) are on the right. The numbers that repeat across the columns
for each method name indicate a specific set of arguments for that method. For instance, the
showInputDialog row shows a 3 in the Parent Component column, Message column, Title
column, and Message Type column. Therefore, the showInputDialog method has one version
defined like this:
public static String showInputDialog(Component parentComponent, Object message,
String title, int messageType)
Note With the exception of two of the showInputDialog() methods, the parent component argument
is required for all method varieties. The message argument is the only one required for all without exception.
What good is a pop-up dialog without a message?
With the way the different showXXXDialog() methods are defined, you don't need to bother
with discovering the selected button yourself, or even the user input. The return value for the
various methods is one of the following: nothing ( void return type), an int from Table 9-1, a
String , or an Object , depending on the type of dialog box shown.
Caution There is a significant difference between the JOptionPane constructors and the factory
methods: The option type and message type arguments are reversed.
 
Search WWH ::




Custom Search