import java.awt.*;
import java.awt.event.*;
class ActionDemo
{
private Frame f;
private Button b;
ActionDemo()
{
init();
}
public void init()
{
f=new Frame("我的窗口");
b=new Button();
f.setBounds(100,200,500,600);
f.add(b);
f.setLayout(new FlowLayout());
myEvent();
f.setVisible(true);
}
public void myEvent()
{
f.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
System.out.println("是窗口关闭的");
System.exit(0);
}
});
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.println("是按钮关闭的");
System.exit(0);
}
});
}
public static void main(String[] args)
{
ActionDemo a=new ActionDemo();
}
}
|