package lesson3;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class TetsKeyListener {
public static void main(String[] args) {
new KeyFrame();
}
}
class KeyFrame extends Frame{
public KeyFrame()
{
setBounds(1,2,300,400);
setVisible(true);
this.addKeyListener(new KeyAdapter() {
//键盘按下出现事件
public void keyPressed(KeyEvent e) {
int keycode=e.getKeyCode();
//获取那个按键按下
if(keycode==KeyEvent.VK_UP)
{
System.out.println("你按下了上键");
}
}
});
}
}
Java图像化——键盘监听
最新推荐文章于 2022-10-04 22:19:31 发布