#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Hi, how can I check whether a number that is transformed by a wrapper class is negati


    Hi,
    I used the following code to check whether a input number is negative or not.
    But it's not working.
    Can anyone please help me?

    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;

    private JTextField theLength; //a type of JTextField
    private JLabel theLabel //a type of JLabel

    public static double stringToDouble(String stringObject)
    {
    return Double.parseDouble(stringObject.trim());
    }


    public void actionPerformed(ActionEvent e)
    {
    if ((stringToDouble(theLength.getText())) < 0)
    {
    theLabel.setText("the number is negative.");
    }
    }
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Is this all the code? You never have an event so the code won't run.
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    348

IMN logo majestic logo threadwatch logo seochat tools logo