标题:KeyListener什么时候会失效啊??
只看楼主
流浪小白
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2017-3-2
结帖率:0
 问题点数:0 回复次数:0 
KeyListener什么时候会失效啊??
import java.awt.*;
import java.awt.event.*;

public class TextKey {
    public static void main(String[] args) {
        new KFrame().lauchFrame();
    }
}

class KFrame extends Frame {
    public void lauchFrame() {
        setLayout(new FlowLayout());
        Button b = new Button("请点一下我!");
        Label l = new Label("请观看");
        setBounds(100,100,300,400);
        add(b);
        add(l);
        b.addActionListener(new ActionMonitor());
        this.addKeyListener(new KeyMonitor());
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                setVisible(false);
            }
        });
        setVisible(true);
    }
   
    class ActionMonitor implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            System.out.println("谢谢你来点我!");
        }
    }
   
    class KeyMonitor extends KeyAdapter {
        public void keyPressed(KeyEvent e) {
            int keycode = e.getKeyCode();
            if(keycode == KeyEvent.VK_UP) {
                System.out.println("再见!");
            }
            //System.out.println("再见!");
        }
    }
}  为什么我这个KeyListener触发不了?
搜索更多相关主题的帖子: public import 
2017-03-02 20:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-474703-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018593 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved