进度条Demo

 

 1 package threadAndRunnable;
 2 
 3 import java.awt.BorderLayout;
 4 
 5 import javax.swing.JFrame;
 6 import javax.swing.JLabel;
 7 import javax.swing.JProgressBar;
 8 
 9 public class jindutiao extends JFrame {
10 
11     // JProgressBar的使用
12     private static JProgressBar progress;
13 
14     public jindutiao() {
15         setTitle("进度条的使用");
16         setBounds(100, 100, 300, 78);
17         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18         progress = new JProgressBar();
19         // 显示进度文本
20         progress.setStringPainted(true);
21         getContentPane().add(progress, BorderLayout.CENTER);
22         final JLabel jl = new JLabel("产品正在升级...");
23         getContentPane().add(jl, BorderLayout.NORTH);
24         setVisible(true);
25     }
26 
27     public static void main(String[] args) {
28         new jindutiao();
29         // 设置进度条为不确定样式
30         progress.setIndeterminate(true);
31         for (int i = 0; i < 100; i++) {
32             try {
33                 Thread.sleep(1000);
34             } catch (InterruptedException e) {
35                 // TODO Auto-generated catch block
36                 e.printStackTrace();
37             }
38             progress.setValue(i);
39         }
40         progress.setIndeterminate(false);
41         progress.setString("升级完成!");
42     }
43 }

 

 

 

 

posted @ 2018-04-29 14:35  消失的那两年  阅读(315)  评论(0编辑  收藏  举报