I'm trying to validate a jtextbox so that it will only except numbers, full stops, backspace and enter.
This is the code that i have come up with reading up on KeyEvent class, but when i test the text box it will still let me type the letter "n" any help and or direction on this issue would be greatly appreciated. (Note - all other events are consumed.)
private void fastPassExtraKeyTyped(java.awt.event.KeyEvent evt) {
char c = evt.getKeyChar(); // on key press event, gets the character used
// sets what is valid, if NOT one of these described, then consume event and play sound
if (!(Character.isDigit(c) || (c == KeyEvent.VK_PERIOD) || (c == KeyEvent.VK_DECIMAL) || (c == KeyEvent.VK_BACKSPACE) || (c == KeyEvent.VK_DELETE)))
{
getToolkit().beep(); // sound made if wrong button pressed to alert user
evt.consume();// key press will be consumed
}
this is also my first post to stackoverflow iv mainly been lurking in the background reading up on issues that i have come across and not had to ask questions as they have already been answered