Laughing

 

java进度条

import javax.swing.*;
public class pb2
{
   static JProgressBar pb;
   JLabel l;
   JDialog d;
   public pb2()
   {
    d=new JDialog();
    d.setTitle("进度条:");
    pb=new JProgressBar();
    d.add(pb);         //将进度条加入到对话框中
    d.setSize(300,89);
    d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
   
    Thread t=new Thread(new Runnable()
    {
    public void run()
    {
    d.setVisible(true);
    }
    }) ;
    t.start();        //启动一个线程运行对话框
   
   }
   public static void main(String a[])
   {
    new pb2();
    for(int i=0;i<=100;i++)
    {    
     pb.setValue(i);          //设置进度
     try
   {
    Thread.sleep(15);   //睡眠15毫秒,这样才看得出效果,如果是其他的则不需要睡眠,比如说下载、上传、复制
   }
   catch (InterruptedException e)
   {
    e.printStackTrace();
   }
     if(i==100) i=0;         //从头开始不断重复
    }
   }
}

posted on 2012-02-18 13:39  巨富一生  阅读(569)  评论(0编辑  收藏  举报

导航