I have a problem with KeyListener in java. Any key is woking, but ‘Tab’ key is not working. I dont know it’s not working.
Here is my code :
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.addKeyListener(new MyKeyListener());
frame.setSize(300,300);
frame.setVisible(true);
}
static class MyKeyListener implements KeyListener {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key Pressed: " + e.getKeyCode());
}
@Override
public void keyReleased(KeyEvent e) {
}
}
}
New contributor
Vương Nguyễn Đình is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.