30-08-2011, 12:27 PM
Code:
/* Text Validation */
import java.awt.*;
import java.applet.*;
public class lawte extends Applet
{
numberTextField ntext1;
Button b1;
class numberTextField extends TextField
{
public numberTextField(int cols)
{
super( cols );
}
public boolean keyDown(Event evt,int key)
{
char keychar = ( char ) key;
if(( keychar > '0' ) && ( keychar < '9' ))
return super.keyDown(evt, key);
else
return true;
}
}
public void init()
{
ntext1 = new numberTextField( 20 );
b1 = new Button( "CLEAR" );
add( ntext1 );
add( b1 );
setForeground( Color.yellow );
setBackground( Color.red );
}
public boolean action(Event evt, Object obj)
{
if( evt.target == "CLEAR" )
{
ntext1.setText(" ");
return true;
}
else
return false;
}
}