I'm trying to do an error check on a JTextField where the correct
input can be -999 to 1000. I've figured out how to check for "" &
length >4, but I'm completely lost as to how to do the "-" and check
to make sure the answer is numeric and not alpha. I'm supposed to be
using "String" methods for my error checks. Here's what I've gotten
so far:
public void actionPerformed (ActionEvent ae)
{
int inputTemp=0;//initialization of the sourceTemp to zero
if (tempInput.getText().equals(""))
//if user doesn't make a temp entry, show error msg
{
JOptionPane.showMessageDialog(null,"Please Enter Temp to
convert", "InputError", JOptionPane.ERROR_MESSAGE);
tempInput.setText("");
tempInput.grabFocus();
return;
}
if (tempInput.getText().length()>4)
//if user enters a temp greater than 4 char, show error msg
{
JOptionPane.showMessageDialog(null, "Value is out of
range", "Value Error", JOptionPane.ERROR_MESSAGE);
tempInput.setText("");//set the tempInput text field to
blank
tempInput.grabFocus();//set the focus to tempInput field
return;
}
else???????
{
for (int i = 0; i < tempInput.getText().length(); i++)
{
StringBuffer tempIn = new StringBuffer(tempInput.getText());
if (tempIn.charAt(i) = "-")
{
}
}
}
//if the input is good, I have a series of if statements to do
calculations dependent upon which radio button isSelected();