请各位高手指教:
我做了一个GUI应用程序,
启动时需要些时间,
怎样运用JProgressBar在程序启动前提示启动进度?

解决方案 »

  1.   

    单独开个线程来控制JProgressBar,进度值的大小 = 已运行时间/总共需要运行的时间。
      

  2.   

    我有也有楼上momo1985一样的疑问!
      

  3.   

    很简单啊,如下
    定义public static JProgressBar progress = new JProgressBar();在打开界面时开一个线程,写
    progress.setMinimum(0);
    progress.setMaximum(13);注意这个13是你程序打开时都需要几个步骤,如查是几就写几比如先需读数据库取值,则取完值后
    progress.setValue(1);
    再进行界面布局
    progress.setValue(2);
    等等以此类推不就行了
      

  4.   

    /**
     * @(#)ProgressTest.java
     *
     *
     * @author 张栋芳QQ271536394
     * @version 1.00 2008/3/13
     */import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.JProgressBar;
    public class ProgressTest extends JDialog{
    public JProgressBar jpb;
    public  int Max=100;
    public  int Min=0;
    public  int Count=1;
    public JButton bStart;
        public ProgressTest() {
           
        
         Container con=(JPanel)this.getContentPane();
         con.setLayout(null);
         bStart=new JButton("开始");
         bStart.setBounds(10,10,70,30);
         bStart.addActionListener(new MyActionListener());
        
         jpb=new JProgressBar();
         jpb.setBounds(80,20,300,20);
         jpb.setMaximum(Max);
         jpb.setMinimum(Min);
         jpb.setAutoscrolls(true);
         jpb.setStringPainted(true);//进度字
         //jpb.setValue(50);
         con.add(bStart);
         con.add(jpb);
         this.setSize(400,300);
         this.setTitle("进度条的小程序");
         this.setLocationRelativeTo(this);
         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         this.setVisible(true);
        
        }
        public static void main(String[] args){
         ProgressTest test=new ProgressTest();
        }
        private class MyActionListener implements ActionListener{
         public void actionPerformed(ActionEvent e){
         if(e.getSource().equals(bStart)){
         System.out.println ("ok");
             UpThread thread=new UpThread();
         thread.start();
         }
         }
        }
        
    class UpThread extends Thread{
    public UpThread(){ }
        public void run(){
         Count=Min;
         while(Count<=Max){
         Count++;
             jpb.setValue(Count);
         try{
         if(Count<40){
         this.sleep(50);
         }
         if(Count>=40&&Count<70){
         this.sleep(200);
         }
         if(Count>=70){
         this.sleep(50);
         }
        
         }catch(Exception ae){
         ae.printStackTrace();
         }
         }
        
        
        }
    }}