import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class TestKeyListener {
public static void main(String[] args) {
new KeyFrame();
}
}
class KeyFrame extends Frame{
public KeyFrame(){
setBounds(100,100,200,300);
setVisible(true);
this.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
int keyCode=e.getKeyCode();
//记录每一个键盘操作对应的代码
System.out.println(keyCode);
//判断按下的是否为对应键
if(keyCode==KeyEvent.VK_UP)
System.out.println("KeyFrame.keyPressed");
}
});
}
}