Home | » | Java | » | Advance Java | » | Java Swing II | » | Input Dialog Boxes |
---|
An input dialog box asks a question and uses a text field to capture the response. The easiest way to create an input dialog is with a call to the showInputDialog(Component, Object) method. The arguments are the parent component and the string, component, or icon to display in the box. The input dialog method call returns a string represents the user's response.
The user can create an input dialog box with the showInputDialog(Component, Object, String, int) method.
The arguments the method takes are as follows:
- The title to display in the dialog box title bar.
- One of the five class variables describing the type of dialog box: ERROR_MESSAGE, INFORMATION_MESSAGE, PLAIN_MESSAGE, QUESTION_MESSAGE, or WARNING_MESSAGE.
Example:
The following statement creates an input dialog box using the method:
Option Dialog Boxes
The most complex of the dialog boxes is the option dialog box, which combines the feature of all the other dialogs. It can be created with the showOptionDialog(Component, Object, String, int, int, Icon Object[]) method.
The arguments to this method are as follows:
- The parent component of the dialog.
- The text, icon or component to display.
- A string to display in the title bar.
- The type of box, using the class variable YES_NO_OPTION or YES_NO_CANCEL_OPTION or the literal 0 if other buttons will be used instead.
- The icon to display, using the class variables ERROR_MESSAGE, INFORMATION_MESSAGE, PLAIN_MESSAGE, QUESTION_MESSAGE, or WARNING_MESSAGE, or the literal 0 if none of these should be used.
- An Icon object to display instead of one of the icons in the preceding argument.
- An array of object holding the components or the other objects that represent the choices in the dialog box, if YES_NO_OPTION or YES_NO_CANCEL_OPTION are not being used.
- The object representing the default selection if YES_NO_OPTION or YES_NO_CANCEL_OPTION are not being used.
The last two arguments enable the user to create a wide range of choices for the dialog box. The user can create an array of buttons, labels, text fields, or even a mixture of different components as an object array. These components are displayed using the flow layout manager.
Example:
The following example accepts information through dialog boxes from the user regarding the Site Title, Site Address and a choice of buttons that helps determine whether the site is a Personal, Commercial or an Unknow site.
C:\>jdk1.4\bin>javac InputDialogBoxes.java
C:\>jdk1.4\bin>java InputDialogBoxes
|
||||
Download Complete Program |
Thanks for sharing valuable information.
ReplyDeleteJava Training with Placements