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.