zoukankan      html  css  js  c++  java
  • java中的key事件监听机制

    package com.at221;
    
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    
    import javax.swing.JFrame;
    
    public class TestKey {
        public static void main(String[] args) {
            JFrame f = new JFrame();
            f.addKeyListener(new MyKeyListener());
            f.setVisible(true);
            
        
            f.setSize(300, 300);
        }    
    }
    
    class MyKeyListener extends KeyAdapter{
        public void keyTyped(KeyEvent e) {//当键盘敲击某个按键时产生的事件:
            System.out.println(e.getKeyChar());
        }
        public void keyPressed(KeyEvent e) {//当键盘按下某个键产生的事件;
            
    //        System.out.println("hello!");
        }
        public void keyReleased(KeyEvent e) {//当键盘上的某个按键被释放时产生的时间;
    //        System.out.println("byebye!!!");
        }
    }
  • 相关阅读:
    Dice 5 ==> dice 7
    Dice 7 ==> dice 5
    100 floors 2 eggs
    Determine overlapping rectangles
    Product of integers
    Maximum profit of stocks
    样式表
    20170508
    2017年05月07
    The second day of school
  • 原文地址:https://www.cnblogs.com/zhaoningzyn/p/6882021.html
Copyright © 2011-2022 走看看