import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
public class EventModelDemo implements ActionListener{
JLabel tips=new JLabel("请单击下面的按钮");
JButton b1=new JButton("确定");
JButton b2=new JButton("取消");
public static void main(String[]args){
EventModelDemo demo=new EventModelDemo();
demo.initUI();
}
void initUI(){
BaseFrame f=new BaseFrame("事件处理模型演示");
f.setLayout(new FlowLayout());
b1.addActionListener(this);
b2.addActionListener(this);
f.add(tips);
f.add(b1);
f.add(b2);
f.showMe();
}
public void actionPerform(ActionEvent e){
if(e.getSource()==b1){
tips.setText("你单击了”"+b1.getText()+"”");
}else if(e.getSource()==b2){
tips.setText("你单击了“"+b2.getText()+"”");
}
}
}
在EventModelDemo出提示:The type EventModelDemo must implement the inherited abstract method ActionListener.actionPerformed(ActionEvent)
你继承自ActionListener接口,所以你要实现ActionListener接口中的方法,你肯定有的方法还未实现
我按照它的提示添加未实现的方法,然后将你actionPerform(ActionEvent e)里的代码复制进去,把你的注释掉就没有报错了
很奇怪,我也不知道为什么是这样
@override
public void actionPerform(ActionEvent e){