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.");
}
}