In java JOptionPane class is used to show Message and also used to get Input from user
Message Box
There are different type of Message Box are available Normal,Error and Warning message box
JOptionPane.showMessageDialog("your Message","Title");
Error Message
JOptionPane.showMessageDialog("your Message","Title",JOptionPane.ERROR_MESSAGE);
Warning Message
JOptionPane.showMessageDialog("your Message","Title",JOptionPane.WARNING_MESSAGE);
Input Box
In order to get a value from user. we can use showInputDialog() Method.
we have to Pass current frame object to that msg
String value=JOptionPane.showInputDialog(fr,"Plz enter Value ");
Input Box with Default value
String value=JOptionPane.showInputDialog(fr,"Plz enter Value ","Default value");
Confirm Dialog
This can be used with following options
Yes No
Retry Ignore Cancel
OK Cancel
Ex for YES NO confirm Dialog
int result=JOptionPane.showConfirmDialog(fr,"Do you Want to Save it","Save",JOptionPane.YES_NO_OPTION);
Note :
here,
result contains 0 or 1..
o refers YES and 1 refers NO
fr -> frame object
"Do you Want to Save it", -> Question
"Save", ->Header
JOptionPane.YES_NO_OPTION -> Option
Thank you
No comments:
Post a Comment