I use this code to restrict the input only for numbers, but if the first key I press is a letter, the code let me enter that letter, only one time, then when I erase it I cannot input anymore letters, what is wrong with the code? I want to imput only numbers.
amount.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
char c = e.getKeyChar();
if (!(Character.isDigit(c)))
e.consume();
}
});
I added the two closing parentheses, still the same results, here is a video