import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonCounter extends JFrame{
  private JButton button=new JButton("1");
  
  public ButtonCounter(String title){
    super(title);
    //为JButton注册ActionEvent的监听器
    button.addActionListener(new ActionListener(){  //定义一个内部类
        public void actionPerformed(ActionEvent evt){
          int count=Integer.parseInt(button.getText());
          button.setText(new Integer(++count).toString());  //把JButton的标号加1
        }
      }
    );

    add(button);
    setSize(100,100);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  public static void main(String args[]){
    new ButtonCounter("Hello");
  }
}


/****************************************************
 * 作者：孙卫琴                                     *
 * 来源：<<Java面向对象编程>>                       *
 * 技术支持网址：www.javathinker.net                *
 ***************************************************/
