当前位置: 代码迷 >> Java Web开发 >> 关于Thread。sleep()的请教
  详细解决方案

关于Thread。sleep()的请教

热度:547   发布时间:2011-03-07 21:29:31.0
关于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  

----------------解决方案--------------------------------------------------------
再次求教....
----------------解决方案--------------------------------------------------------
回复 2楼 wangchunbao
有人 会的 叫我一下....
----------------解决方案--------------------------------------------------------
  相关解决方案