我编写了一个程序来显示一个带有标签、文本字段和按钮的窗口。当鼠标单击文本字段时,应该调用程序 VirtualKeyboardTest.java。
import java.awt.*;
import java.awt.event.*;
class WindowText implements MouseListener
{
public static void main(String[] args)
{
Frame f=new Frame("New Window");
f.setSize(500,300);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
Panel p = new Panel();
Panel p1 = new Panel();
Label lb = new Label("Click on textfield");
TextField tf = new TextField(20);
tf.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
new VirtualKeyboardTest();
}
public void mousePressed(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
});
p.setLayout(new FlowLayout());
p.add(lb);
p.add(tf);
Button Submit=new Button("Submit");
p.add(Submit);
p1.add(p);
f.add(p1,BorderLayout.CENTER);
}
}
但是当我尝试编译这个程序时,我得到了一个错误
WindowText.java:4: WindowText is not abstract and does not override abstract method mouseExited(java.awt.event.MouseEvent) in java.awt.event.MouseListener
class WindowText implements MouseListener
^
1 error
我不明白为什么我会得到这个错误,即使我已经覆盖了 MouseListener 中的每个方法。