Joptionpane usage-Java

Source: Internet
Author: User

Joptionpane usage -- Java

 

Simple Application of joptionpane:

1. first introduce the package:

Import javax. Swing. joptionpane;

2. Add the following code:

Object [] Options = {"OK", "cancel", "help "};

// Customize the available buttons

Int response = joptionpane. showoptiondialog (null, "This is an option dialog box. You can select the number of your buttons.", "option dialog box title", joptionpane. yes_option, joptionpane. question_message, null, options, options [0]);

If (response = 0 ){

Joptionpane. showmessagedialog (null, "you have pressed the OK button", "message elimination", joptionpane. information_message); // message dialog box

} Else if (response = 1 ){

Joptionpane. showmessagedialog (null, "you have pressed the cancel button", "message", joptionpane. information_message );

} Else if (response = 2 ){

Joptionpane. showmessagedialog (null, "you have pressed the Help button", "message", joptionpane. information_message );

}

String SA = joptionpane. showinputdialog (null, "Enter the first INTEGER :");

// Input dialog box

String sb = joptionpane. showinputdialog (null, "enter the second INTEGER :");

Int IA, IB;

Try {// catch exceptions thrown by parselnt ()

IA = integer. parseint (SA );

} Catch (exception e ){

IA = 0;

}

Try {

IB = integer. parseint (SB );

} Catch (exception e ){

IB = 0;

}

Int Ic = IB + ia;

Joptionpane. showmessagedialog (null, "the sum of the two numbers is:" + IC, "message", joptionpane. information_message );

Simply learn the simple application of the three joptionpane dialogs. You just need to know about it. It's not very difficult. Remember it several times. In addition, you do not have to perform any other exercises when you use them. It is not too late to query them.

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.