Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Need help with an error check

  Asked By: Lourdes    Date: Jul 21    Category: Java    Views: 761

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);

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
tempInput.grabFocus();//set the focus to tempInput field
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();



No Answers Found. Be the First, To Post Answer.

Didn't find what you were looking for? Find more on Need help with an error check Or get search suggestion and latest updates.