日期:2014-05-17 浏览次数:20766 次
package com.tmzs.pc.jsoup;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.FileNotFoundException;
import javax.swing.JFrame;
public class KeyBoardListener extends JFrame {
public KeyBoardListener() throws FileNotFoundException {
this.setTitle("监听键盘事件");
this.setSize(800, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
char ch = e.getKeyChar();
int num = e.getKeyCode() ;
System.out.println("键盘="+ch+",代表数字="+num);
}
});
}
public static void main(String[] args) throws FileNotFoundException {
new KeyBoardListener();
}
}