MessageBox in Java, static class direct reference

Source: Internet
Author: User

Text: MessageBox in Java, direct reference to static classes

Package Cisdi.mes.wrm.mcode.serviceImpl;

Import javax.persistence.Entity;
Import Javax.swing.JOptionPane;

@Entity
public class Mcodetest {

/**
* @param <WrmMtlUomClassesTlService>
* @param args
*/
public static void main(string[] args) throws exception{

Joptionpane.showmessagedialog (NULL, "Insert database failed!") "," Message Prompt ", joptionpane.error_message);
Joptionpane.showmessagedialog (NULL, "INSERT database successfully!") "," Message Prompt ", joptionpane.information_message);

Joptionpane.showmessagedialog (NULL, "Insert failed!");
}
}

The class run as Java application. can see the effect

Following

Reproduced from

http://blog.163.com/[email protected]/blog/static/110682210201171222738457/

Using the Joptionpane class inside the javax.swing, there are several static methods available, such as

1 showmessagedialog(Component parentcomponent,Object message)

2 showmessagedialog(Component parentcomponent,Object message, String title, int MessageType)

And so on, these methods are static, you can call directly, specifically, you should look at the API documentation, I would like to cite a case to help the application:

Import Javax.swing.JOptionPane;

public class MessageBox

{

public static void Main (String args[])

{

Joptionpane.showmessagedialog (NULL, "Sample dialog!");

}

}

Several ways to pop up a dialog box in swing _joptionpane.showmessagedialog, etc. 2008-06-26 09:32

In swing, business-based considerations include a dialog box that restricts the user's behavior and prompts the user for action.

The Joptionpane class is provided in swing to implement the functionality of the MessageBox like the Windows platform, as well as in Java, using the various static methods in the Joptionpane class to generate a variety of standard dialogs for displaying information, Ask questions, warnings, user input parameters and other functions. These dialog boxes are modal dialogs.
Confirmdialog---Confirm the dialog box, ask the question, then confirm by the user (press "Yes" or "No" button)
INputdialog---Prompt to enter text
Messagedialog---display information
Optiondialog--Combine the other three types of dialog boxes.
These four dialogs can be displayed using Showxxxdialog (), such as Showconfirmdialog () display confirmation dialog, Showinputdialog () Display Input Text dialog box, Showmessagedialog () Display Information dialog box , Showoptiondialog () Displays the Selective dialog box. The parameters they use are described below:
①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.
②message:Indicates the descriptive text to display in the dialog box
③string title: Title bar text string.
④component:Components to display in the dialog box (such as buttons)
⑤icon: The icon to be displayed in the dialog box
⑥messagetype:The following values can generally be error_message, Information_message, Warning_message, Question_message, Plain_message,
⑦optiontype:It determines the button options to be displayed at the bottom of the dialog box. Generally can be default_option, yes_no_option, Yes_no_cancel_option, Ok_cancel_option.
Usage examples:
(1) Display Messagedialog
Joptionpane.showmessagedialog (NULL, "Descriptive text displayed in dialog box", "title bar text string", joptionpane.error_message);
(2) Display Confirmdialog
Joptionpane.showconfirmdialog (NULL, "Choose one", "Choose One", joptionpane.yes_no_option);
(3) Display Optiondialog: This dialog box can be set by the user to the number of individual buttons and return the user to click the number of buttons (starting from 0 count)
object[] options = {"OK", "Cancel", "Help"};
int Response=joptionpane.showoptiondialog (This, "This is an option dialog box, the user can choose their own number of buttons", "Options dialog box title", Joptionpane.yes_option, Joptionpane.question_message, NULL, Options, options[0]);
if (response==0)
{This.settitle ("You pressed the OK button");
}
else if (response==1)
{This.settitle ("You pressed the Cancel button");
}
else if (response==2)
{This.settitle ("You pressed the Help 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");

MessageBox in Java, static class direct reference

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.