[java] view plain copy
1. /**
2. * java swing 之进度条的使用
3. * @author gao
4. */
5. package com.gao;
6.
7. import java.awt.FlowLayout;
8.
9. import javax.swing.JFrame;
10. import javax.swing.JPanel;
11. import javax.swing.JProgressBar;
12. import javax.swing.border.EmptyBorder;
13.
14. public class JProgressBarDemo extends JFrame {
15. public JProgressBarDemo(){
16. this.setTitle("进度条的使用");
17. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18. this.setBounds(100, 100, 250, 100);
19. new JPanel();
20. new EmptyBorder(5,5,5,5));
21. this.setContentPane(contentPane);
22. new FlowLayout(FlowLayout.CENTER,5,5));
23. final JProgressBar progressBar=new JProgressBar();
24. true);
25. new Thread(){
26. public void run(){
27. for(int i=0;i<=100;i++){
28. try{
29. 100);
30. catch(InterruptedException e){
31. e.printStackTrace();
32. }
33. progressBar.setValue(i);
34. }
35. "升级完成!");
36. }
37. }.start();
38. contentPane.add(progressBar);
39. this.setVisible(true);
40. }
41. public static void main(String[]args){
42. new JProgressBarDemo();
43. }
44. }