this.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
System.out.println(e.getKeyChar() + ", " + e.getKeyCode()
+ ", " + KeyEvent.getKeyText(e.getKeyCode())
+ ", isActionKey: " + e.isActionKey());
}
});
private static void createAndShowGUI() {
JFrame frame = new JFrame("Frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
JPanel test = new Test();
frame.getContentPane().add(test);
frame.setVisible(true);
test.requestFocus(); // 注意,与上面的这一句不能反
}