首页 > 代码库 > Java 进度条

Java 进度条

public class jprogess3s extends JFrame {
 
       public static   JPanel contentPane;
       private static JProgressBar progressBar;
      
       public static JLabel picture;
       public jprogess3s() throws InterruptedException {
            setTitle( "Drawing");
            setDefaultCloseOperation(JFrame. HIDE_ON_CLOSE);
            setBounds(100, 100, 464, 98);
             contentPane = new JPanel();
             contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
            setContentPane( contentPane);
             contentPane.setLayout(null);
            JPanel panel = new JPanel();
            panel.setBounds(5, 5, 433, 52);
             contentPane.add(panel);
            panel.setLayout( null);
             progressBar = new JProgressBar(0,300);
             progressBar.setBounds(10, 5, 406, 36);
             progressBar.setStringPainted(true);
            panel.add( progressBar);
            setLocationRelativeTo( null);
             this.setVisible(true);
            
            Thread t = new Thread(new thread1());
            t.start();
            
            
      }
  public static class thread1 implements Runnable{
               
 
                   public void run()
                {
                        
                        for (int i=0; i<=3; i++)
                        {
                               //Progressively increment variable i
                               progressBar.setValue(i*100); //Set value
                               progressBar.repaint(); //Refresh graphics
                               try {
                                          Thread. sleep(1000);
                                    } catch (InterruptedException e) {
                                           // TODO Auto-generated catch block
                                          e.printStackTrace();
                                    }
                        }
    }
      }
}