1. It belongs to the javax. swing package.
2. function: customizes four standard dialogs of different types.
ConfirmDialog confirmation dialog box. Ask the question and confirm it by the user (Press "Yes" or "No)
InputDialog prompt input text
MessageDialog display information
OptionDialog combines the other three dialog box types.
3. The four dialogs can be displayed using showXXXDialog. For example:
ShowConfirmDialog () shows the confirmation dialog box,
ShowInputDialog () displays the input text dialog box,
ShowMessageDialog () display information dialog box,
ShowOptionDialog () displays the selective dialog box.
4. parameter description.
(1) ParentComponent: indicates the parent window object of the dialog box, which is generally the current window.
You can also use the default Frame as the parent window if it is null. In this case, the dialog box is set in the middle of the screen. (2) message: indicates the descriptive text to be displayed in the dialog box (3) String title: title Provision String. (4) Component: components to be displayed in the dialog box (such as buttons) (5) Icon: Icon to be displayed in the dialog box (6) messageType (Icon ):
ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
QUESTION_MESSAGE, PLAIN_MESSAGE, and (7) optionType: button options displayed at the bottom of the dialog box.
DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION, and OK _CANCEL_OPTION.
5. Use instances: (1) display MessageDialog
JOptionPane. showMessageDialog (null, "information to be displayed", "title", JOptionPane. ERROR_MESSAGE );
(2) display ConfirmDialog
JOptionPane. showConfirmDialog (null, "message", "title", OptionPane. YES_NO_OPTION );
(3) display OptionDialog:
In this dialog box, you can set the number of buttons and return the serial number of each button you click (counting starts from 0)
Object [] options = {"query", "deposit", "withdrawal", "quit "};
Int response = JOptionPane. showOptionDialog (null, "select business type", "ATM", JOptionPane. YES_OPTION, JOptionPane. PLAIN_MESSAGE,
Null, options, options [0]);
If (response = 0)
{JOptionPane. showMessageDialog (null, "you pressed the query button ");}
Else if (response = 1)
{JOptionPane. showMessageDialog (null, "you have pressed the deposit button ");}
Else if (response = 2)
{JOptionPane. showMessageDialog (null, "you have pressed the withdrawal button ");}
Else if (response = 3)
{JOptionPane. showMessageDialog (null, "you have pressed the exit button ");}
(4) display InputDialog to allow users to enter
String inputValue = JOptionPane. showInputDialog ("Please input a value ");
(5) display InputDialog to allow users to selectively Input
Object [] possibleValues = {"First", "Second", "Third "};
// Select a project
Object selectedValue = JOptionPane. showInputDialog (null,
"Choose one", "Input", JOptionPane. INFORMATION_MESSAGE,
Null, possibleValues, possibleValues [0]);
SetTitle ("You have pressed" + (String) selectedValue + "project ");}