Java Reference
In-Depth Information
the dialog shown will be displayed:
When you click on the
OK
button, whatever you entered in the text field will be returned and stored in
input
-
"
This is the input
"
in this case. If you click on the
Cancel
button,
null
will be returned. Note
that this is not the same as no input. If you click on
OK
without entering anything in the text field, a
reference to an empty
String
object will be returned.
showInputDialog(Component parent, Object message)
This produces the same dialog as the previous method, but with the component you specify as the first
argument as the parent of the dialog.
showInputDialog(Component parent, Object message,
String title, int messageType)
In this case the title of the dialog is supplied by the third argument, and the style of the message is
determined by the fourth argument. The values for the fourth argument can be any of those discussed
earlier in the context of message dialogs. For instance, you could display the dialog shown with the
following statement:
String input = JOptionPane.showInputDialog(null, "Enter Input:",
"Dialog for Input", JOptionPane.WARNING
_
MESSAGE);
The data that you enter in the text field is returned by the
showInputDialog()
method when the
OK
button is pressed as before.
showInputDialog(Component parent, Object message,
String title, int messageType,
Icon icon, Object[] selections,
object initialSelection)