zoukankan      html  css  js  c++  java
  • java 键盘监听事件

    package test;
    
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    
    public class test extends JFrame {    
        private MyPanel1 myPanle;    
        public static void main(String[] args) {
            test Test = new test();
        }
        
        public test() {
            myPanle = new MyPanel1();
            this.add(myPanle);
            this.addKeyListener(myPanle);
            this.setSize(400, 300);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setVisible(true);
        }
    
    }
    
    class MyPanel1 extends JPanel implements KeyListener{
    
        @Override
        public void keyTyped(KeyEvent e) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public void keyPressed(KeyEvent e) {
            
                System.out.println(e.getKeyCode());
            if (e.getKeyCode()==32){
                System.out.println("空格");
            } 
        }
    
        @Override
        public void keyReleased(KeyEvent e) {
    
        }
    
    }
    今日事今日毕
  • 相关阅读:
    数据应用
    Python邮件脚本
    函数
    tab模块
    python登陆,注册小程序
    三元运算+lambda表达式
    计算机基础
    软件测试概要
    asyn_fifo
    perl 对ENV环境变量的使用
  • 原文地址:https://www.cnblogs.com/gjack/p/8306988.html
Copyright © 2011-2022 走看看