The class below shows how to limit a textfield to accept only numeric values.

Java Code:
public class app extends java.applet.Applet {
  TextField textField1;

  public void init() {
    setLayout(new FlowLayout());
    textField1 = new TextField(10);
    add(textField1);
    }

  public boolean handleEvent(Event event) {
     if (event.target==textfield1 && event.id == Event.KEY_PRESS) {
       char c = (char)event.key;
       if (c >= '0' && c <= '9') {
         // keep digit
         return super.handleEvent(event);
         } 
       else if (Character.isISOControl(c)) {
         // keep control character (like del, bksp)
         return super.handleEvent(event);
         } 
       else {
         // discard Character
         return true;
         }
       }
     return super.handleEvent(event);
     }
}