标题:求助 程序 错在哪里?怎么改
只看楼主
niu91
Rank: 2
等 级:论坛游民
帖 子:64
专家分:44
注 册:2009-7-25
结帖率:83.33%
 问题点数:0 回复次数:1 
求助 程序 错在哪里?怎么改
程序代码:
import java.awt.event.*;
import java.awt.*;
public class AdapterCounter extends Frame{
    private Button button=new Button("1");
    
    public AdapterCounter(String title){
        super(title);
        //把MyMouseListener的实例注册为Button的监听器
        button.addMouseListener(new MyMouseListener(2));
        
        addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent evt){
                System.exit(0);//结束程序
            }
        });
        
        add(button);
        setSize(100,100);
        setVisible(true);
    }
    public static void main(String[] agrs){
        new AdapterCounter("Hello");
    }
}

class MyMouseListener extends MouseAdapter{
    private int step;        //决定Button上的标号每次增加的步长
    public MyMouseListener(int step){
        this.step=step;
    }
    
    public void mousePressed(MouseEvent evt){
        Button button=(Button)evt.getSource();
        int count=Integer.parseInt(button.getLabel());
        //把Button上的标号加step
        button.setLabel(new Integer(step+count).toString());
    }
}
搜索更多相关主题的帖子: 注册 title 
2011-11-19 22:35
让我们飞
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:40
专家分:119
注 册:2011-1-9
得分:0 
你想问什么?
   没发现什么错无啊?
2011-11-26 14:13



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




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

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