View Single Post
  #2 (permalink)  
Old 05-20-2007, 12:19 PM
levent levent is offline
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Double has parseDouble method which tries to parse a String as a Double. You need to put it inside a try-catch block since it throws NumberFormatException.

You can write logic inside catch since it is called if the value is not a valid double!

Here is an example code:

Code:
double value; try { // String textValue = the string from your JTextField value = Double.parseDouble(textValue); // if the code gets to here, it was recognizable as a double } catch(NumberFormatException e) { // if the code gets to here, it was NOT recognizable as a double }
Reply With Quote