I'm trying to validate a TextField, where I only want to allow numbers on the TextField. My code looks like this:
public void handle(KeyEvent evt) {
String character = evt.getCharacter();
if(!character.equals("1")) {
JOptionPane.showMessageDialog(null,evt.getCharacter());
evt.consume();
}
}
This doesn't consume the event :( Is this a bug? Is there another way to do this?