JOptionPane
Helps to easily pop up a standard dialog box that asks the user for a value or notifies themAlthough many of the methodsJOptionPane
The class may appear complex, but almost all of the use of this class is for the following static
One-way call :
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/07/BA/wKiom1nOQBiRwJ0SAAA3CwO7ADo237.png "title=" 002_ . png "alt=" Wkiom1noqbirwj0saaa3cwo7ado237.png "/>
showinternalxxx style appears, this style uses the internal form to save the dialog box. It also defines a number of convenient methods that overload those basic methods and use different parameter lists.
all dialog boxes are modal. Each method blocks the caller until the user interaction is complete showXxxDialog
.
displays an error dialog box that displays the message ' Alert ' :
displays an internal Information dialog box with the message ' Information ' :
JOptionPane.showInternalMessageDialog(frame, "information","information", JOptionPane.INFORMATION_MESSAGE);
displays an information panel with options of "yes/no" with message ' Choose one ' :
displays an internal Information dialog box with the options "Yes/no/cancel", message ' Please choose one ', and a title message :
JOptionPane.showInternalConfirmDialog(frame,
"Please choose one", "Information",JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
Displays a warning dialog box with options OK, cancel,title ' Warning ', and message ' Click OK to continue ':
Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
Joptionpane.default_option, Joptionpane.warning_message,null, options, options[0]);
Displays a dialog box that asks the user to type a String:
Displays a dialog box that asks the user to select a String:
Object[] possibleValues = { "First", "Second", "Third" };
Object selectedvalue = Joptionpane.showinputdialog (null,"Choose One", "Input"
Joptionpane.information_message, Null,possiblevalues, possiblevalues[0]);
Create and use Joptionpane directly
//specific parameter meanings can be consulted in Java document joptionpane pane = new joptionpane (arguments); pane.set.xxxx (...); // configure jdialog dialog = pane.createdialog ( Parentcomponent, title); dialog.show (); object selectedvalue = pane.getvalue (); if (selectedValue == NULL) return closed_option; //if there is not an array of option buttons: if (options == null) { if (selectedValue Instanceof integer) return ((Integer) SelectedValue). Intvalue (); return closed_option; } //if there is an array of option buttons: for (Int counter = 0, maxcounter = options.length; counter < maxCounter; counter++) { if (Options[counter].equals ( SelectedValue)) return counter; } return CLOSED_OPTION;
Reference: Online API documentation
This article is from the "Guardian" blog, please be sure to keep this source http://acevi.blog.51cto.com/13261784/1969841
Different types of popup dialog boxes in Java