import java.awt.*;
import java.awt.event.*;
public class face implements ActionListener{
        Frame f;
        Button b1,b2;
        public static void main(String arv[]){
                new face();
        }
        public face(){
                f=new Frame("Button");
                f.setLayout(new GridLayout(2,2));
               
                b1=new Button("Left");
                b1.setActionCommand("b1");
                b1.addActionListener(this);
               
                b2=new Button("Ritht");
        b2.setActionCommand("b2");
        b2.addActionListener(this);
               
            f.add(b1);
            f.add(b2);
                f.pack();
                f.setVisible(true);
        }
        public void actionPerformaed(ActionEvent e){
                String cmd=e.getActionCommand();
                if(cmd.equals("b1"));
                     b2.setEnabled(!b2.isEnabled());
                else
                     b1.setEnabled(!b1.isEnabled());
        }}
为什么会提示face需要设置为抽象类呢?

解决方案 »

  1.   

    public void actionPerformaed(ActionEvent e){ 
                    String cmd=e.getActionCommand(); 
                    if(cmd.equals("b1")); 
                         b2.setEnabled(!b2.isEnabled()); 
                    else 
                         b1.setEnabled(!b1.isEnabled()); 
            }
    ->
    public void actionPerformed(ActionEvent e){ 
                    String cmd=e.getActionCommand(); 
                    if(cmd.equals("b1")); 
                         b2.setEnabled(!b2.isEnabled()); 
                    else 
                         b1.setEnabled(!b1.isEnabled()); 
            }
      

  2.   


    //你得实现这个方法啊,不实现它认为你想把这个类当作是抽象类呢,因为你没有实现接口的方法!抽象类和类的区别你应该知道吧
    public void actionPerformed(ActionEvent arg0) {
    // TODO Auto-generated method stub

    } if(cmd.equals("b1")); //还有这里多了个分号!
      

  3.   

    格式还不好控制 ,就两个地方 
    1 是那个方法的名字 你拼写错误  
    是actionPerformed2 是 if那句后面的分号不能有
      

  4.   

    原来方法名字写错了....
    改为actionPerformed
      

  5.   

    你的这个类没有抽象方法,但是继承别的类,如果这个类没有实现父类中的抽象方法,那么它必须也要定义为抽象类,楼上已经说出你的错误之处了,你没有实现父类中的actionPerformed方法,原因是你把方法名给写错,哈哈!