java - Testing whether an input is a number -


i have program, whenever type , hit enter, prints out in window (it's command prompt). however, due few problems calculator function i'm trying add, if user input number, want totally ignore

    input = new jtextfield();     input.seteditable(true);     input.setforeground(color.white);     input.setcaretcolor(color.white);     input.setopaque(false);      input.addactionlistener(new actionlistener(){          public void actionperformed(actionevent e) {              string text = input.gettext();              if (text.length() >= 1){                  print(text + "\n", false);                  docommand(text);                 scrollbottom();                 input.selectall();             }          }     }); 

you check if text number regex that:

text.matches("[1-9][0-9]*"); 

i hope helps.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -