标题:关于Thread。sleep()的请教
取消只看楼主
wangchunbao
Rank: 2
等 级:论坛游民
帖 子:24
专家分:10
注 册:2010-11-6
结帖率:25%
 问题点数:0 回复次数:2 
关于Thread。sleep()的请教
我的代码如下::
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

class counterchild extends JFrame {
    JPanel pmain,ptext,pbutton;
    private JTextField jft=new JTextField(5);
    JButton jbs,jbc;
    public counterchild(){
        pmain=new JPanel();
        ptext=new JPanel();
        pbutton=new JPanel();
        
        //jft;
        jbs=new JButton("start");
        jbc=new JButton("close");
        
        setContentPane(pmain);
        ptext.add(jft);
        pbutton.add(jbs);
        pbutton.add(jbc);
        
        pmain.add(ptext,BorderLayout.NORTH);
        pmain.add(pbutton,BorderLayout.SOUTH);
        
        jbs.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {              
              addcounter();              
            }
         });
         
        jbc.addActionListener(new ActionListener()
        {        
            public void actionPerformed(ActionEvent e)
            {                                       
              System.exit(0);
            }
         });
        
        
        
    }
    public void addcounter()
    {        
        for(int i=1;i<=50;i++)
        {
            try{
                jft.setText(Integer.toString(i));
                Thread.sleep(100);
               }            
            catch(Exception ee){}
        }
        
    }   
}

public class counter{
    public static void main(String args[]){
        counterchild ct=new counterchild();
        ct.setSize(100,150);
        ct.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ct.show();
    }
}

问题:上述代码运行是为什么没有显示数据?、thread.sleep()出问题了吗???
搜索更多相关主题的帖子: close 
2011-03-07 21:29
wangchunbao
Rank: 2
等 级:论坛游民
帖 子:24
专家分:10
注 册:2010-11-6
得分:0 
再次求教....
2011-03-08 14:41
wangchunbao
Rank: 2
等 级:论坛游民
帖 子:24
专家分:10
注 册:2010-11-6
得分:0 
回复 2楼 wangchunbao
有人 会的 叫我一下....
2011-03-09 15:50



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




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

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