This time I posting about showConfirmDialog.
This Dialog similar to showMessageDialog. But this is 'confirm'.
'showConfirmDialog' has 4 options.
Option is...
- DEFAULT_OPTION
- YES_NO_OPTION
- YES_NO_CANCEL_OPTION
- OK_CANCEL_OPTION
I add source code to showMessageDialog test source.
There are new source's layout!!
Left side is test for showMessageDialog.
Right side is test for showConfirmDialog.
Okay, go to source.
- @Override
- //showMessageDialog
- 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);
- }
- //showconfirmDialog
- else if(e.getSource()==btnDefaultoption){
- JOptionPane.showConfirmDialog(null,"THIS IS DEFAULT OPTION","DEFAULT TITLE",JOptionPane.DEFAULT_OPTION);
- }else if(e.getSource()==btnYesnooption){
- JOptionPane.showConfirmDialog(null,"THIS IS YES_NO OPTION","YES_NO TITLE",JOptionPane.YES_NO_OPTION);
- }else if(e.getSource()==btnYesnocanceloption){
- JOptionPane.showConfirmDialog(null,"THIS IS YES_NO_CANCEL OPTION","YES_NO_CANCEL TITLE",JOptionPane.YES_NO_CANCEL_OPTION);
- }else if(e.getSource()==btnOkcanceloption){
- JOptionPane.showConfirmDialog(null,"THIS IS OK_CANCEL OPTION","OK_CANCEL TITLE",JOptionPane.OK_CANCEL_OPTION);
- }
- //showconfirmDialog
- }
JOptionPane.showConfirmDialog(Component
arg0, Object
arg1, String
arg2, int arg3)
Component arg0 : location of dialog. So generally null.Object arg1 : confrim message.
String arg2 : title
int arg3 : showConfirmDialog's option.
Look at Line 18, 21, 23, 25
This is making dialog.
Click to DEFAULT_OPTION
Click to YES_NO_OPTION
Click to YES_NO_CANCEL_OPTION
Click to OK_CANCEL_OPTION
Default icon is QUESTION_MESSAGE.
If you want change the icon, add parameter for icon.
- JOptionPane.showConfirmDialog(null,"THIS IS DEFAULT OPTION","DEFAULT TITLE",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE);
And showConfirmDialog returned integer value.
You can use this return value for choice situation.
- int choose=JOptionPane.showConfirmDialog(null,"THIS IS YES_NO OPTION","YES_NO TITLE",JOptionPane.YES_NO_OPTION);
- }
This is YES_NO_OPTION.
If you choose 'yes'
If you choose 'no'
No comments:
Post a Comment