• Post Reply Bookmark Topic Watch Topic
  • New Topic

about JOptionPane input values?  RSS feed

 
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?

 
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.
 
Marshal
Posts: 58454
178
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!