java - JOptionPane Input Dialog how to decide if the value is 2 or JOptionPane.CANCEL_OPTION -
i use following code inputdialog:
string c = joptionpane.showinputdialog("select number",joptionpane.ok_option);
i want user uses integervalues between 0 , 100. handle following code:
while(notallowed){ try{ int t =integer.parseint(c); if(t==joptionpane.cancel_option) { notallowed=false; cancel=true; } if(t<=100 && t>0 &¬allowed) notallowed=false; } catch( exception err) {} if(notallowed) c = joptionpane.showinputdialog("only numbers between 1 , 100 allowed"); }
now if uses types number 2 clicking cancel button because value of joptionpane.cancel_option 2. how can find out if cancel clicked or input value 2.
joptionpane returns null if user clicks on cancel. otherwise value returned. figured out using small example:
public class joptionpanetest { public static void main(string[] args) { object obj = joptionpane.showinputdialog(null, "test", "test-text"); system.out.println(obj); } }
Comments
Post a Comment