package GUI;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class Test13_Key {
public static void main(String[] args) {
new KeyFrame();
}
}
class KeyFrame extends Frame{
public KeyFrame(){
setSize(500,500);
setVisible(true);
// 键盘监听器
this.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
int KeyCode=e.getKeyCode(); // 键盘的每一个按键都对应着唯一的KeyCode
if (KeyCode==KeyEvent.VK_DOWN) // VK.XXX 对于着不同的键码,简易记法,不用记具体的码的数值
System.out.println("你按下了下键");
}
});
}
}
标签:13,java,awt,public,键盘,KeyFrame,import,监听
From: https://www.cnblogs.com/zhanjianhai/p/17620421.html