import java.applet.*;
import java.awt.*;
import java.awt.event.*;  

public class tablet_events4 extends Applet implements TextListener {

TextField textField;
Label label;

public void init() 
{
	setBackground(new Color(225,225, 255));
	textField = new TextField(20);
	textField.addTextListener(this);
	add(textField);
	label = new Label("          ");
	label.setForeground(Color.red);
	add(label);
	textField.requestFocus();
}

void displayCorrectness()
{
	if (getDoubleFromString(textField.getText()) < -0.01)
	{
		textField.setForeground(Color.red);
		label.setText("Error");
	}
	else
	{
		textField.setForeground(Color.black);
		label.setText("          ");
	}
}

public void textValueChanged(TextEvent te)
{
	displayCorrectness();
}

double getDoubleFromString(String s)
{
	s = s.trim();
	if (s.equals("") || s == null) return (-1.0);
	try
	{
		return (Double.valueOf(s).doubleValue());
	}
	catch (Exception e)
	{
		return(-1.0);
	}
}
}  // END OF Class tablet_events4
