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)