Link to home
Start Free TrialLog in
Avatar of dkim18
dkim18

asked on

Double.parseDouble behavior

this is something I don't get...

I declared like this:
minXSinTField = new JTextField("0.0", 4);

and then I am using this func to test input validation.
isValidInput(minXSinTField);

This is the func.
  public boolean isValidInput(JTextField tf) {
    boolean result = true;
    try {
      Double.parseDouble(tf.getText());
      result = true;
      System.out.println("in try section");
      System.out.println(result);
    }
    catch (NumberFormatException ex) {
      result = false;
      System.out.println("in  catch section");
      System.out.println(result);
    }
    System.out.println("before return;");
    System.out.println(result);
    return result;
  }

Now, when I enter any string this func returns true.
From other pane's textfields, when I enter string this func returns false.

I don't know why...
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Please post input
Avatar of Webstorm
Webstorm

Hi dkim18,


Try this:

  public boolean isValidInput(JTextField tf) {
    try {
      Double.parseDouble(tf.getText());
      return true;
    }
    catch (Exception ex) {
      return false;
    }
  }
Avatar of dkim18

ASKER

Webstorm,

when I entered string, it still returns true...

CHEJ,

minXSinTField = new JTextField("0.0", 4);

ASKER CERTIFIED SOLUTION
Avatar of Webstorm
Webstorm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dkim18

ASKER

when I enter string "input"
the outcome was:

Input is (0.0)
Avatar of dkim18

ASKER

I found error.
I am sharing same private members for two panes...
that was why...

thanks anyway,