| 为什么我添加了键盘监听器,按下去一点反应都没的,具体看代码吧 在DOS窗口运行的时候,按什么键都么反应的,我代码和老是的一样的啊,为什么呢?复制代码import java.awt.*;
import java.awt.event.*;
public class MouseKeyEvent {
        private Frame f;
        private Button but;
        MouseKeyEvent() {
                init();
        }
        public void init() {
                f = new Frame("zxj");
                f.setBounds(300, 330, 500, 200);
                f.setLayout(new FlowLayout());
                but = new Button("hh");
                f.add(but);
                f.setVisible(true);
                myEvent();
        }
        public void myEvent() {
                f.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                                System.exit(0);
                        }
                });
                but.addKeyListener(new KeyAdapter() {
                        public void KeyPressed(KeyEvent e) {
                                System.out.println(e.getKeyChar() + "...." + e.getKeyCode());
                        }
                });
        }
        public static void main(String[] args) {
                MouseKeyEvent mke = new MouseKeyEvent();
        }
}
 |