Try this one
e.getKeyChar() != KeyEvent.VK_BACK_SPACE
in place of
e.getKeyCode() != KeyEvent.VK_BACK_SPACE
in keyTyped()
method.
Directly from JavaDoc of KeyEvent
The getKeyChar method always returns a valid Unicode character or CHAR_UNDEFINED. Character input is reported by KEY_TYPED events: KEY_PRESSED and KEY_RELEASED events are not necessarily associated with character input. Therefore, the result of the getKeyChar method is guaranteed to be meaningful only for KEY_TYPED events.
For key pressed and key released events, the getKeyCode method returns the event's keyCode. For key typed events, the getKeyCode method always returns VK_UNDEFINED. The getExtendedKeyCode method may also be used with many international keyboard layouts.
For more info read here about Key Event.