I'm starting to schedule events in java and I have a problem with getKeyCode ().
In a JFrame of my program I added this.addKeyListener(lamina1);
(lamina1 is an instance of a class that inherits from JPanel)
this is the listener code:
public void keyTyped(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_ENTER){
chars.add(numcaracteres, true);
}else{
char txt=e.getKeyChar();
chars.add(numcaracteres, txt);
}
numcaracteres++;
repaint();
}
(chars is an instance of ArrayList)
The problem I have is that if(e.getKeyCode()==KeyEvent.VK_ENTER)
does not work, because when I press enter, it does not execute the code inside the if, I tried to change VK_ENTER
for other values to check if it was only with enter, but the same thing happens with any other value