package newgui; 

 

  import javax.swing.*; 

 

  import java.awt.event.*; 

 

  public class SimpleGui1B implements ActionListener {//捕捉到点击按钮的动作 需要实现ActionListener接口 

 

  JButton button; 

 

  JFrame frame; 

 

  int i=0; 

 

  public static void main(String[] args) { 

 

    

 

  SimpleGui1B a =new SimpleGui1B(); 

 

  a.go(); 

 

  } 

 
 

 

  public void go() 

 

  { frame = new JFrame();//创建框架 

 
 

 

  button= new JButton();//创建按钮 

 

  button.addActionListener(this);//监听按钮 

 

  frame.getContentPane().add(button);//将按钮加入该框架内 

 

  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置关闭按钮的动作 

 

      frame.setSize(200, 200);//设置按钮的大小 

 

  frame.setVisible(true);//设置按钮可见性 

 

  } 

 
 

 

  public void actionPerformed( ActionEvent event)//响应方法 

 
 

 

  {   i++; 

 

  button.setText( String.valueOf(i));//改变按钮的文字 

 

  frame.setSize( 100+10*i, 100+10*i);//设置按钮大小 

 

  } 

 

  }