1, belongs to the javax.swing package.
2, Function: Customize four different kinds of standard dialog box.
Confirmdialog Confirmation dialog box. Ask a question and then be confirmed by the user (press "Yes" or "No" button)
Inputdialog Prompt to enter text
Messagedialog Display Information
Optiondialog combination of the other three dialog box types.
3. These four dialogs can be displayed using Showxxxdialog (). Such as:
Showconfirmdialog () Displays a confirmation dialog box,
Showinputdialog () Displays the Input Text dialog box,
Showmessagedialog () Displays the Information dialog box,
Showoptiondialog () Displays the Selective dialog box.
4, parameter description.
(1) Parentcomponent: Indicates the parent window object of the dialog box, typically the current window.
You can also null to use the default frame as the parent window, at which point the dialog box is set to the center of the screen.
(2) Message: Indicates the descriptive text to be displayed within the dialog box
(3) string title: Title bar text string.
(4) Component: The component to be displayed in the dialog box (such as a button)
(5) Icon: Icons to be displayed in the dialog box
(6) MessageType (icon):
Error_message, Information_message, Warning_message,
Question_message, Plain_message,
(7) Optiontype: Button options displayed at the bottom of the dialog box.
Default_option, Yes_no_option, Yes_no_cancel_option, Ok_cancel_option.
5, use Example:
(1) Display Messagedialog
Joptionpane.showmessagedialog (NULL, "message content to display", "title", Joptionpane.error_message);
(2) Display Confirmdialog
Joptionpane.showconfirmdialog (NULL, "message", "title", Optionpane.yes_no_option)
(3) Display Optiondialog:
This dialog can be used by the user to set the number of individual buttons and return the user to click the number of buttons (counting starting from 0)
object[] options = {"Enquiry", "deposit", "withdrawal", "exit"};
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 pressed the deposit button");
Else if (Response = = 2)
{Joptionpane. Showmessagedialog (null, "You pressed the withdrawal button");
Else if (Response = = 3)
{Joptionpane. Showmessagedialog (null, "You pressed the exit button");
(4) Display inputdialog to allow user input
String Inputvalue = joptionpane.showinputdialog ("Please input a value");
(5) Display Inputdialog to allow user to enter selectively
Object[] PossibleValues = {"First", "Second", "third"};
User's selection item
Object SelectedValue = Joptionpane. Showinputdialog (null,
"Choose One", "Input", Joptionpane. Information_message ,
null, PossibleValues, possiblevalues[0]);
Settitle ("You pressed" + (String) selectedvalue+ "project");}
Transferred from: http://blog.sina.com.cn/s/blog_993d254201013pgh.html
Use of the Joptionpane class in Java