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需要设置为抽象类呢?
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需要设置为抽象类呢?
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());
}
//你得实现这个方法啊,不实现它认为你想把这个类当作是抽象类呢,因为你没有实现接口的方法!抽象类和类的区别你应该知道吧
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
} if(cmd.equals("b1")); //还有这里多了个分号!
1 是那个方法的名字 你拼写错误
是actionPerformed2 是 if那句后面的分号不能有
改为actionPerformed