package com.wang.gui.lesson02;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
//键
public class TestKeyListener {
public static void main(String[] args){
new KeyFrames();
}
}
class KeyFrames extends Frame{
public KeyFrames(){
setBounds(1,2,300,400);
setVisible(true);
this.addKeyListener(new KeyAdapter() {
//鼠标按下
@Override
public void keyPressed(KeyEvent e) {
//获得键盘下的键是哪一个,当前的码
int keyCode = e.getKeyCode();//不需要去记录这个数值,直接使用静态属性VK_XXX
System.out.println(keyCode);
if (keyCode == KeyEvent.VK_UP){
System.out.println("你按下了上键");
}
//根据按下不同操作,产生不同结果;
}
});
}
}