猿问

怎样实现java的键盘监听啊,求大神看一下我的部分代码,看看还需要添加什么。代码实现在键盘上敲一下,就能显现“键盘输入”的功能

package jiamian;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

class jianpan extends JPanel implements KeyListener{

JPanel panel =new JPanel();

public void keyTyped(KeyEvent e) {

}

public void keyPressed(KeyEvent e) {

System.out.println("键盘输入");

}

public void keyReleased(KeyEvent e) {

}

public void paint(Graphics g){

super.paint(g);

}

jianpan(){

panel.addKeyListener(this);

}

}

public class heh {

public static void main(String[] args){

jianpan jian=new jianpan();

}


}


疾风一闪
浏览 2090回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答