I am trying to create an event handler for two JTextFields to only allow numerical input. It consumes all letter but for some reason the "n" key still gets through. I have the spaghetti code below. Can anyone tell me what i'm not getting?
public void keyTyped(KeyEvent in) { char input = in.getKeyChar(); if (in.getSource() == scaleField){ if (!(Character.isDigit(input) || (input==KeyEvent.VK_BACK_SPACE) || (input==KeyEvent.VK_DELETE) || (input==KeyEvent.VK_DECIMAL) || (input==KeyEvent.VK_PERIOD)) || (scaleField.getText().contains(".") && (input==KeyEvent.VK_DECIMAL || input==KeyEvent.VK_PERIOD))){ in.consume(); } }else if (!(Character.isDigit(input) || (input==KeyEvent.VK_BACK_SPACE) || (input==KeyEvent.VK_DELETE))){ in.consume(); } }