• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about JOptionPane input values?

 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a JOptionPane used for input of a numeric value...

like,




what if the user entered a String instead of a numeric value? how can i trace it? and put out another JOptionPane message dialog saying that the input is invalid?

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at Integer#parseInt's API, what does it say when the parameter is not a parsable int ?
 
Aron Jhed Amiscosa
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:If you look at Integer#parseInt's API, what does it say when the parameter is not a parsable int ?


Nvm.. Thanks.
I got it now.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49808
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may be able to find a regular expression from the Integer API and use that to try validating the JOptionPane input. That might be quicker than awaiting an Exception. But you will still get problems if somebody enters 3000000000 for an int.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic