java - How to issue a warning if required text field is empty? -


i trying make executable jbutton (which opens new window)radiobutton chosen , textfiled filled within specific range (the textfield should 1800 2013) . radiobuttons made default choise now, cannot figure out how can return warning textfield should filled (a number between 1800 , 2013) , if there run program.

edit: if code is:

jframe .... jpanel ....  jtextfield txt = new jtextfield(); jbutton button = new jbutton("run"); button.addactionlistener(new actionlistener(){ public void actionperformed(actionevent e) { //do things here } }); txt.addfocuslistener(new focuslistener() {       .... } 

how can use itemstatelistener. should define listener , what?

public void actionperformed(actionevent e)   {       string s = txt.gettext();       char[] carr = s.tochararay();       arraylist<character> chars = new arraylist<character>();       (char c : carr)           if (c.isdigit())               chars.add(c);       carr = new char[chars.size()];       (int = 0;i<chars.size();i++)           carr[i] = char.get(i);       s = new string(carr);       txtfield.settext(s);       if (s.equals(""))       {           // issue warning           return;       }       int input = integer.parseint(s);       if (input >=  1800 && input <= 2013)       {           // stuff       }   }   

basically, read string in text field, remove non-numeric characters it, , proceed if in range specified.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -