按钮事件监听

来源:互联网 发布:数据类型转化php 编辑:程序博客网 时间:2024/05/02 06:44
import java.awt.*;
import java.awt.event.*;
public class  EventTest
{
public static void main(String[] args){
Frame f=new Frame();
Button b=new Button();
b.addActionListener(new ButtonListener());
Button close=new Button("c");
close.addActionListener(new closeListener());
f.setLayout(new FlowLayout());
f.add(b);
f.add(close);
f.setSize(200,100);
f.setVisible(true);
}
}
class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e){
System.out.println("you chick it");
}
}
class closeListener implements ActionListener
{
public void actionPerformed(ActionEvent e){
System.exit(0);
}


}