This post about showInputDialog and showOptionDialog of JOptionPane class.
This method is simple than previous posting method.
I added button for test(showInputDialog and showOptionDialog).
showInputDialog test 2-type.
First button is just input dialog.
Second is choice dialog.
showOptionDialog is similar to showConfirmDialog.
But showoptionDialog is choice the option.
We change the option value.
Okay go to source code.
If you don't understand JButton, visit my post JButton.
This is first showInputDialog source.
- //showInputDialog
- else if(e.getSource()==btnShowinputdialog){
- String text=JOptionPane.showInputDialog(null,"What's your hobby?","hobby",JOptionPane.INFORMATION_MESSAGE);
- }
Method is
JOptionPane.showInputDialog(Component arg0, Object arg1, String arg2, int arg3)
Component arg0 : location. generally null.
Object arg1 : showInputDialog's Message.
String arg2 : showInputDialog's Title.
int arg3 : showInputDialog's Icon.
And showInputDialog's return value is String.
So, I using this return value.
Line 4: Display showInputDialog's return value.
Click to showInputDialog
I write 'basketball' and click to 'Yes'.
This second showInputDialog's source
- }else if(e.getSource()==btnShowmultiinputdialog){
- Object choose=JOptionPane.showInputDialog(null,"what is best cell phone?" ,"Best phone",JOptionPane.QUESTION_MESSAGE,null,choiceOne,choiceOne[0]);
- }
Second showinputDialog's Method is
JOptionPane.showInputDialog(Component
arg0, Object
arg1, String
arg2, int arg3, Icon
arg4, Object[]
arg5, Object
arg6)
Component arg0 : Location dialog. Generally null.Object arg1 : showInputDialog's Message.
String arg2 : showInputDialog's Title.
int arg3 : showInputDialog's icon.
Icon arg4 : maybe null.
Object[] arg5 : Spinner's item.
Object arg6 : Default show item.
Click to showMultiInputDialog.
Line 2 : My item is 'SAMSUNG-GALAXY', APPLE-IPhone', 'LG-G', 'Pantech-VEGA'.
Line 3: I choose default item SAMSUNG-GALAXY. So. default show 'SAMSUNG-GALAXY'.
I choose APPLE-IPhone and click to 'Yes'.
This is showOptionDialog's source code.
- //showOptionDialog
- else if(e.getSource()==btnShowoptiondialog){
- int response=JOptionPane.showOptionDialog(null, "What's your phone?","Select Phone",JOptionPane.DEFAULT_OPTION ,JOptionPane.QUESTION_MESSAGE, null, option, option[0]);
- if(response==0){
- }else if(response==1){
- }else if(response==2){
- }
- }
- //showOptionDialog
JOptionPane.showOptionDialog(Component
arg0, Object
arg1, String
arg2, int arg3, int arg4, Icon
arg5, Object[]
arg6, Object
arg7)
Component arg0 : location. Generally null.Object arg1 : showOptionDialog's message.
String arg2 : showOptionDialog's title.
int arg3 : message option. Generally JOptionPane.DEFAULT_OPTION.
int arg4 : showOptionDialog's icon.
Icon arg5 : maybe null.
Object[] arg6 : option items.
Object arg7 : default selected item.
And showOptionDialog's return value is integer type.
Click to showOptionDialog.
Line 3 : I made items 'IPhone5S', 'Galaxy Note3', 'G3'.
Line 4 : I select default item 'IPhone5S'. show Dialog.
And I click to 'Galaxy Note3'.
No comments:
Post a Comment