in my project i have to accept only numeric values in a JTextField is there any way to do this ?

how to accept only numeric values in a JtextField, is there are any methods presents in the java for performing task please help me…

this is one of the way for accepting the only numeric values into the JTextfield.

 

JTextField textField = new JTextField() {

  public void processKeyEvent(KeyEvent ev) {

    char c = ev.getKeyChar();

    if (c >= 48 && c <= 57) { // c = '0' ... c = '9'

      super.processKeyEvent(ev);

    }

  }

};