wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes about JOptionPane input values? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about JOptionPane input values?" Watch "about JOptionPane input values?" New topic
Author

about JOptionPane input values?

Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

If you look at Integer#parseInt's API, what does it say when the parameter is not a parsable int ?


[My Blog]
All roads lead to JavaRanch
Jhedzkie Skies
Ranch Hand

Joined: Oct 28, 2009
Posts: 118
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

Joined: Oct 13, 2005
Posts: 36507
    
  16
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about JOptionPane input values?
 
Similar Threads
Inputbox
converting a double value
Triangular Output
Why is request.getParameterValues not working for me?
JTable numeric validation