标题:求高手指点,注册监视器了怎么JButton没反应?
取消只看楼主
伊人醉
Rank: 1
等 级:新手上路
帖 子:9
专家分:3
注 册:2011-8-20
结帖率:100%
已结贴  问题点数:5 回复次数:0 
求高手指点,注册监视器了怎么JButton没反应?
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;
/*
 * 在窗口有一个按钮点击这个按钮,按钮的点击次数会显示在这按钮上
 * */

public class Teste_5 {
    static Action a;
    public static void main(String[] args) {
        a=new Action();
    }
}
class Action implements ActionListener{
        JFrame f;
        JButton butt1;
        int i=0;
    Action(){
        JFrame f=new JFrame();
        JButton butt1=new JButton("i");
        f.setSize(400, 500);
        f.setLayout(new FlowLayout());
        Container con=f.getContentPane();
        con.add(butt1);
        butt1.addActionListener(this);
        f.setVisible(true);
    }
   
    public void actionPerformed(ActionEvent e){
        if(e.getSource()==butt1){
        int n=Integer.parseInt(butt1.getText());   
          n++;
            butt1.setText(String.valueOf(n));
        }
    }
}
搜索更多相关主题的帖子: class 监视器 public import 
2011-09-21 08:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-350468-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.675620 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved