我看了一个MSDN,然后写了这个程序,不知为什么没什么反应当我敲键时!import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class temp extends JFrame implements KeyListener{
  public int a;
  public JLabel code;
  public Container c;
  public String temp;
  public temp()
  {
      super("temp");
      code=new JLabel("ok");
      c=getContentPane();
      //c.add(code);
      temp=" ";
      int a=0;
     setSize(200,200);
      show();
  }
  public void paint(Graphics g)
  {
       setSize(200,200);
       c.add(code);
       //String temp=" ";
       temp=temp+a;
       code.setText(temp);
  }
  public  void keyPressed (KeyEvent e)
  {a=e.getKeyCode();
   repaint();}
  public  void keyReleased (KeyEvent e)
  {}
  public  void keyTyped (KeyEvent e)
  {}
  public static void main (String args[])
  {
    temp app=new temp();
    app.addWindowListener(new WindowAdapter()
     {public void windowClosing(WindowEvent e)
       {System.exit(0);}});
  }}