注册 登录
编程论坛 J2EE论坛

关于Thread。sleep()的请教

wangchunbao 发布于 2011-03-07 21:29, 705 次点击
我的代码如下::
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()出问题了吗???
2 回复
#2
wangchunbao2011-03-08 14:41
再次求教....
#3
wangchunbao2011-03-09 15:50
回复 2楼 wangchunbao
有人 会的 叫我一下....
1