this is my code, which is written inside my applet
KeyListener keyListener = new KeyListener()
{
public void keyPressed(KeyEvent keyEvent)
{
validate valid=new validate();
valid.errorMessage(txt_district_id, keyEvent);
}
public void keyReleased(KeyEvent keyEvent)
{
}
public void keyTyped(KeyEvent keyEvent)
{
}
};
txt_district_id.addKeyListener(keyListener);
and code of validate class is
public class validate
{
public String errorMessage(KeyEvent keyEvent,JTextField txt)
{
int keyCode = keyEvent.getKeyCode();
String keyText = KeyEvent.getKeyText(keyCode);
//msg.setText(title + " : " + keyText + " / " + keyEvent.getKeyChar());
if(keyCode > 47 && keyCode < 58)
{
txt.setEditable(true);
}
else
{
txt.setEditable(false);
return "Only Numeric Value Accepted";
}
}
}
everything working properly, but the problem is whenever user input any alphabet the textfield will become disable, and that is my problem. I mean it should like, alphabet can not be entered and textfield should be enabled in any case. Thanks in advance.!!