当前位置:编程学习 > JAVA >>

java例程练习(键盘事件)

import java.awt.*; 
import java.awt.event.*; 
public class TestKeyEvent { 
    public static void main(String[] args) { 
        new KeyFrame().launchFrame(); 
    } 

 
class KeyFrame extends Frame { 
    public void launchFrame() { 
        setSize(200,200); 
        setLocation(200,200); 
        this.addKeyListener(new MyKeyMonitor()); 
        this.setVisible(true); 
    } 
 
    class MyKeyMonitor extends KeyAdapter { 
        public void keyPressed(KeyEvent e) { 
            int keyCode = e.getKeyCode(); 
            if(keyCode == KeyEvent.VK_UP) { 
                System.out.println("UP"); 
            } 
        } 
    } 

 


摘自 Yours风之恋

补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,