package window;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class Window extends JFrame{
public static int num = 0;
public static void main(String[] args) {
new Window();
}
public Window(){
//设置x y坐标
this.setLocation(400, 500);
//设置窗口大小
this.setSize(512, 512);
//设置窗口可见
this.setVisible(true);
//设置窗口关闭后程序停止
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//设置窗口不可移动
this.setResizable(false);
JButton but1 = new JButton("按钮");
final JTextField text1 = new JTextField(10);
Container c = this.getContentPane();
c.setLayout(new FlowLayout());
c.add(text1);
c.add(but1);
ActionListener al = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
num ++;
text1.setText(""+num);
}
};
text1.setText(""+num);
but1.addActionListener(al);
}
}