编写一个窗口程序,窗口中有两个按钮“退出”和“点击”还有一个文本框,当单机退出时结束程序,单机点击

编写一个窗口程序,窗口中有两个按钮“退出”和“点击”还有一个文本框,当单机退出时结束程序,单机点击时文本框中显示该按钮被单机的次数

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
public class ExpFrame extends Frame {    
    int count = 0;
    public ExpFrame() {
        super("单击按钮实验");
        this.setLayout(new FlowLayout());
        Button b1 = new Button("退出");
        Button b2 = new Button("点击");
        TextField tf = new TextField("您单击了0次", 20);
        this.add(b1);
        this.add(b2);
        this.add(tf);
        this.pack(); 
        this.setLocation(300, 300);
        this.setVisible(true);
        b1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ExpFrame.this.setVisible(false);
                System.exit(0);
       
            }
   
        });
        b2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                count ++;
                tf.setText("您单击了" + count + "次");
   
            }
   
        });
    }
    public static void main(String[] args) {
        new ExpFrame();
    } 
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-06-16

您好,你是要这样的效果吗?

追问

对对对

追答

我qq 1263526752

追问

多少?

追答

1263526752 代码有点多,这里发不了

追问

验证问题,你是谁?

哥,赶时间……还有半小时

追答

随便写

本回答被提问者采纳
第2个回答  2015-06-16
8