🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #18586

JProgressBar�����������

#18586
From: Gatorade
Date: Fri, 06 Feb 2004 03:48
73 lines
3215 bytes
������һ��JProgressBar����ʾijЩ����ִ��(ActionThread)��ȣ�
���ڸ���ProgressBar�Ĵ�������:

------------------------------------------------------------------------------
    class ProgressUpdateThread1 extends Thread
    {
        int value;          //ProgressBar value

        Runnable runnable;  //set ProgressBar

        Thread actionThread;//action (do sth, like copy file,etc...)

        
        public ProgressUpdateThread1()
        {
            runnable = new Runnable()
            {
                public void run()
                {
                    progressBar.setValue(value);
                }
            };
            actionThread = new ActionThread();
        }

        public void run()
        {
            boolean finish = false;
            int newValue = -1;
            actionThread.start();
            
            while (!finish)
            {
                try
                {
                    Thread.currentThread().sleep(500);
                    if (null != actionThread)
                    {
                        newValue = actionThread.getActionPercent();
                        if (value != newValue)
                        {
                            value = newValue;
                            System.out.println(" invokeLater to " + value);
                            SwingUtilities.invokeLater(runnable);
                        }
                    }
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
                finish = actionThread.IsFinished();
            }
        }
    }
------------------------------------------------------------------------------
System.out��ӡ������Ϣ������ActionThread��ProgressUpdateThread1ȷʵ
ͬʱ��ִ�У�����ȡ��ִ�н��ֵ
newValue = actionThread.getActionPercent();
Ҳ��ȷ���󣬵��ǽ�����ProgressBarû�����ϸ��£�ֱ�ȵ�actionThreadִ����ϣ�
ProgressBar�ſ�ʼ���¡�

��������ʲôԭ����ν��?

лл!!


--
�� ��Դ:��Ʈ��ˮ�Ƽ� freecity.cnzju.net��[FROM: llsz]
Technical Details
Message-ID: <4AXcb8$A0O@freecity.cnzju.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!sjc70.webusenet.com!news.usenetserver.com!maily.cic.tsinghua.edu.cn!news.ccie.net.cn!Freecity

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,GB
X-Google-Thread: f6cb0,837f03d76fa6e59c,start
X-Google-Attributes: gidf6cb0,public
X-Google-ArrivalTime: 2004-02-05 19:51:58 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!sjc70.webusenet.com!news.usenetserver.com!maily.cic.tsinghua.edu.cn!news.ccie.net.cn!Freecity
From: llsz.bbs@freecity.cnzju.net (Gatorade)
Newsgroups: cn.bbs.comp.lang.java
Subject: JProgressBar�����������
Date: 06 Feb 2004 03:48:13 GMT
Organization: Ʈ��ˮ�Ƽ�
Message-ID: <4AXcb8$A0O@freecity.cnzju.net>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: Java/M.1076038904.A