import java.awt.*;
import java.awt.event.*;
public class MulitListener
{
private Frame myframe=new Frame("测试窗口");
private Button btn1=new Button("按钮1");
private Button btn2=new Button("按钮2");
private TextArea fil=new TextArea(7,8);
public void init()
{
second se=new second();
btn1.addActionListener(new first());
btn1.addActionListener(se);
btn2.addActionListener(new first());
myframe.addWindowListener(new mylistener());
Panel pel=new Panel();
pel.add(btn1);
pel.add(btn2);
myframe.add(pel,BorderLayout.SOUTH);
myframe.add(fil,BorderLayout.CENTER);
myframe.pack();
myframe.setBounds(400,400,400,400);
myframe.setVisible(true);
}
class first implements ActionListener{
public void actionPerformed(ActionEvent e){
fil.append("事件一 "+e.getActionCommand()+"\r\n");
}
}
class second implements ActionListener{
public void actionPerformed(ActionEvent e){
fil.append("事件二 "+e.getActionCommand()+" "+e.getWhen()+"\r\n");
}
}
class mylistener implements WindowListener{
public void windowOpened(WindowEvent e){
fil.append("窗体已打开\n");
}
public void windowDeiconified(WindowEvent e){
fil.append("窗体已恢复\n");
}
public void windowIconified(WindowEvent e){
fil.append("窗体最小化\n");
}
public void windowDeactivated(WindowEvent e){
fil.append("窗体失去焦点\n");
}
public void windowActivated(WindowEvent e){
fil.append("窗体被激活\n");
}
public void windowClosing(WindowEvent e){
fil.append("窗体关闭中\n");
System.exit(0);
}
public void windowClosed(WindowEvent e){
fil.append("窗体已关闭\n");
}
}
public static void main(String[] args)
{
new MulitListener().init();
}
}