Introduction to Java Joptionpane classes _java

Source: Internet
Author: User

1, belong to Javax.swing package.

2, Function: Customize four different kinds of standard dialog box.

Confirmdialog Confirmation dialog box. Ask the question and then confirm by the user (press "Yes" or "No" button)

Inputdialog Prompt to enter text

Messagedialog Display Information

Optiondialog combines three other dialog box types.

3, the four dialog boxes 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 optional dialog box.

4, parameter description.

(1) Parentcomponent: Indicates the parent window object for the dialog box, typically the current window.

You can also use the default frame as the parent window, and the dialog box will be set to the center of the screen.  (2) Message: Indicates the descriptive text (3) string title: Title bar text string to be displayed in the dialog box. (4) Component: In the dialog box to display the components (such as buttons) (5) Icon: In the dialog box to display the icons (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, the use of examples: (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:

The dialog box allows the user to set the number of individual buttons and return the number of buttons that the user clicks (counting starting from 0).

object[] options = {"Inquiry", "deposit", "withdraw", "exit"};

int Response=joptionpane.showoptiondialog (NULL, "Select business Type", "ATM Teller machine", 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 the user to enter

String Inputvalue = joptionpane.showinputdialog ("Please input a value");

(5) Display Inputdialog to allow the user to enter selectively

Object[] PossibleValues = {"A", "Second", "third"};

User's Select item

Object SelectedValue = Joptionpane.showinputdialog (null,

"Choose One", "Input", Joptionpane.information_message,

NULL, PossibleValues, possiblevalues[0]);

Settitle ("You pressed" + (String) selectedvalue+ "project");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.