import java.awt.*;
import java.awt.event.*;public class W4 extends Frame implements ActionListener {
Button btn1,btn2;
TextField f;

W4(){
super("Window4");
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
setSize(350,200);
btn1 = new Button("显示");
btn2 = new Button("退出");
f = new TextField(20);
setLayout(new FlowLayout());
add(f);
add(btn1);
add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
show();
}
public static void main(String args[]){
new W4();
}

public void actionPeformed(ActionEvent e){
f.setText("你按下了“"+e.getActionCommand()+"“按钮");
if(e.getSource() == btn2){
System.exit(0);
}
}}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
该程序编译不过,提示信息为:W4.java:4: W4 is not abstract and does not override abstract method actionPerfor
med(java.awt.event.ActionEvent) in java.awt.event.ActionListener
public class W4 extends Frame implements ActionListener {
       ^
1 error麻烦各位给看下,不知怎么改。

解决方案 »

  1.   

    ActionListener是一个接口,你既然implements了它,就要实现它的所有方法 !
      

  2.   

    W4 is not abstract and does not override abstract method actionPerfor
    就是说你不是抽象的类,不可以重写抽象类中的方法。
      

  3.   

    ActionListener它只有一个方法actionPerformed(),你只要添一句public void actionPerformed(){}应该就可以编译通过了 !
      

  4.   

    public void actionPerformed(ActionEvent e)方法名写错了
      

  5.   

    to interhanchi:接口的话,采用事件适配器或是采用匿名类一般是不用实现它所有方法的。还有你说的那方法试过了,不行。
      

  6.   

    public void actionPeformed(ActionEvent e)这句错了,actionPeformed少写一个r,应该是actionPerformed.
    ^_^. 还有我用1.5编译后,显示:
    F:\>javac W4.java
    注意: W4.java 使用或覆盖了已过时的 API。
    注意: 要了解详细信息,请使用 -Xlint:deprecation 重新编译。F:\>javac -Xlint:deprecation W4.java
    W4.java:25: 警告: [deprecation] java.awt.Window 中的 show() 已过时
                    show();
                    ^
    1 警告
      

  7.   

    编程要细心!
    public void actionPerformed(ActionEvent e){}