关于KeyListener接口的问题
请大家帮我看下下面我写的代码,看看有什么错误啊?为什么总是实现不了按下“1”键显示“hello”,按下“2”键显示“goodbye”,谢谢
import java.awt.*;
import java.awt.event.*;
import javax.swing.JTextArea;
import javax.swing.JFrame;
public class test extends JFrame implements KeyListener{
JTextArea text_Area;
test(String title){
super(title);
int width = 200;
int height = 300;
Point center = GraphicsEnvironment.getLocalGraphicsEnvironment ().getCenterPoint ();
setBounds(center.x - width/2, center.y - height/2, width, height);
setLayout(new GridLayout(2, 1, 0, 0));
JPanel text_Panel = new JPanel();
add(text_Panel);
text_Area = new JTextArea();
text_Area.setEditable (false);
text_Panel.add (text_Area);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void keyTyped(KeyEvent e){
}
public void keyReleased(KeyEvent e){
}
public void keyPressed(KeyEvent e){
switch(e.getKeyCode ()){
case KeyEvent.VK_1:
text_Area.setText ( "Hello ");
break;
case KeyEvent.VK_2:
text_Area.setText ( "goodbye ");
break;