I posting SWING's popup message showMessageDialog of JOptionPane.
JOptionPane has 4-methods
Method Name | Description |
---|---|
showConfirmDialog | Asks a confirming question, like yes/no/cancel. |
showInputDialog | Prompt for some input. |
showMessageDialog | Tell the user about something that has happened. |
showOptionDialog | The Grand Unification of the above three. |
showMessageDialog is default dialog.
showMessageDialog has 5 options.
- ERROR_MESSAGE
- INFORMATION_MESSAGE
- WARNING_MESSAGE
- QUESTION_MESSAGE
- PLAIN_MESSAGE
I making sample source for showMessageDialog test.
I made 5 buttons.
This is JAVA source.
- @Override
- if(e.getSource()==btnErrMsg){
- JOptionPane.showMessageDialog(null,"THIS IS ERROR MESSAGE","ERROR TITLE",JOptionPane.ERROR_MESSAGE);
- }else if(e.getSource()==btnInfoMsg){
- JOptionPane.showMessageDialog(null,"THIS IS INFORMATION MESSAGE","INFORMATION TITLE",JOptionPane.INFORMATION_MESSAGE);
- }else if(e.getSource()==btnWarningMsg){
- JOptionPane.showMessageDialog(null,"THIS IS WARNING MESSAGE","WARNING TITLE",JOptionPane.WARNING_MESSAGE);
- }else if(e.getSource()==btnQuestionMsg){
- JOptionPane.showMessageDialog(null,"THIS IS QUESTION MESSAGE","QUESTION TITLE",JOptionPane.QUESTION_MESSAGE);
- }else if(e.getSource()==btnPlainMsg){
- JOptionPane.showMessageDialog(null,"THIS IS PLAIN MESSAGE","PLAIN TITLE",JOptionPane.PLAIN_MESSAGE);
- }
- }
If you don't know JButton, visit this post How to using JButton of SWING (JAVA)
Line 4,6,8,10,12 is running showMessageDialog.
Component arg0 : location of showMessageDialog.
Object arg1 : Message.
String arg2 : title.
int arg3 : showMessageDialog's option.
Generally Component arg0 is null.
Line 3 : btnErrMsg is ERROR_MESSAGE.
Line 5 : btnInfoMsg is INFORMATION_MESSAGE,
Line7 : btnWarningMsg is WARNING_MESSAGE,
Line9 : btnQuestionMsg is QUESTION_MESSAGE,
Line11 : btnPlainMsg is PLAINE_MESSAGE.
click to ERROR_MESSAGE.
Click to INFORMATION_MESSAGE.
Click to WARNING_MESSAGE
Click to QUESTION_MESSAGE
Click to PLAIN_MESSAGE
How to different??
Just Icon!!
showMessageDialog's option is Icon.
You can make popup-message according to situation using option.
Also possible to using this form.
This form's default option is INFORMATION_MESSAGE.
No comments:
Post a Comment