编写程序,界面如下要求:您单击了第一个按钮,单击另一个按钮,则退出整个程序

如题所述

事件写的有问题,我一修改,你自己看一下吧
package TEST;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class ClicksNumber extends JFrame{

private JButton button=new JButton("请点击");
Container container=this.getContentPane();
private static int i = 0;

public ClicksNumber(){

this.setTitle("欢迎使用");
container.setLayout(new FlowLayout());
button.addActionListener(new ButtonEventHandle());
container.add(button);
this.show();
this.setSize(300,400);
}

class ButtonEventHandle implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
i++;
button.setText("you have clicked this button "+i+"times");
}
}

public static void main(String[] args) {
// TODO Auto-generated method stub
new ClicksNumber();
温馨提示:答案为网友推荐,仅供参考
相似回答