天行健

《周易》曰:
天行健,君子以自强不息(乾卦)
地势坤,君子以厚德载物(坤卦)

常用链接

统计

最新评论

一个JProgressBar的简单例子

 

 

 1 import  javax.swing. * ;
 2 import  java.awt. * ;
 3 import  java.awt.event. * ;
 4 import  javax.swing.event. * ;
 5 import  javax.swing.border. * ;
 6
 7
 8 public   class  JProgressEx  extends  JApplet {
 9   private   int  min = 0 ,max = 100 ;
10    private  JProgressBar pb  =   new  JProgressBar();
11   private  Timer t;
12    private   int  i;
13    JPanel panel  =   new  JPanel();
14    public  JProgressEx() {
15   }

16    public   synchronized   void  setValue() {
17    i = 0 ;
18   }

19    public   synchronized   int  getValue() {
20     return  i;
21   }

22    public   synchronized   void  addValue() {
23    i ++ ;
24   }

25    public   void  setMin() {
26     this .min  =  min;
27   }

28    public   int  getMin() {
29     return  min;
30   }

31    public   void  setMax() {
32     this .max  =  max;
33   }

34    public   int  getMax() {
35     return  max;
36   }

37
38   public   void  init()  {
39     Container cp  =  getContentPane();
40     pb.setMinimum(min);
41     pb.setMaximum(max);
42     pb.setBackground (Color.white);
43     pb.setForeground (Color.red);
44     pb.setStringPainted( true ) ;
45     cp.add(panel.add(pb),BorderLayout.PAGE_START);
46   }

47    public   void  start() {
48    t  =   new  Timer( 100 new  ActionListener()  {
49        public   void  actionPerformed(ActionEvent evt)  {
50          if (getValue() < getMax()) {
51           addValue();
52           pb.setValue(getValue());
53         }
else {
54           setValue();
55           t.stop();
56         }

57     }

58     }
);
59   t.start();
60   }

61    public   static   void  main(String[] args)  {
62    final  JProgressEx pg  =   new   JProgressEx();
63     JFrame frame  =   new  JFrame( " JProgressEx " );
64     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
65     frame.getContentPane().add(pg);
66     frame.setSize( 300 200 );
67     pg.init();
68     frame.setVisible( true );
69     pg.start();
70   }

71 }

72

 


 7
 8 public   class  JProgressEx  extends  JApplet {
 9   private   int  min = 0 ,max = 100 ;
10    private  JProgressBar pb  =   new  JProgressBar();
11   private  Timer t;
12    private   int  i;
13    JPanel panel  =   new  JPanel();
14    public  JProgressEx() {
15   }

16    public   synchronized   void  setValue() {
17    i = 0 ;
18   }

19    public   synchronized   int  getValue() {
20     return  i;
21   }

22    public   synchronized   void  addValue() {
23    i ++ ;
24   }

25    public   void  setMin() {
26     this .min  =  min;
27   }

28    public   int  getMin() {
29     return  min;
30   }

31    public   void  setMax() {
32     this .max  =  max;
33   }

34    public   int  getMax() {
35     return  max;
36   }

37
38   public   void  init()  {
39     Container cp  =  getContentPane();
40     pb.setMinimum(min);
41     pb.setMaximum(max);
42     pb.setBackground (Color.white);
43     pb.setForeground (Color.red);
44     pb.setStringPainted( true ) ;
45     cp.add(panel.add(pb),BorderLayout.PAGE_START);
46   }

47    public   void  start() {
48    t  =   new  Timer( 100 new  ActionListener()  {
49        public   void  actionPerformed(ActionEvent evt)  {
50          if (getValue() < getMax()) {
51           addValue();
52           pb.setValue(getValue());
53         }
else {
54           setValue();
55           t.stop();
56         }

57     }

58     }
);
59   t.start();
60   }

61    public   static   void  main(String[] args)  {
62    final  JProgressEx pg  =   new   JProgressEx();
63     JFrame frame  =   new  JFrame( " JProgressEx " );
64     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
65     frame.getContentPane().add(pg);
66     frame.setSize( 300 200 );
67     pg.init();
68     frame.setVisible( true );
69     pg.start();
70   }

71 }

72

 

posted on 2006-04-10 17:25 重归本垒(Bing) 阅读(1321) 评论(1)  编辑  收藏 所属分类: JAVA文章

评论

# re: 一个JProgressBar的简单例子 2008-11-27 20:47 老欧

谢谢,正需要  回复  更多评论   


标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2006-06-14 09:37 编辑过
 
 

推荐图书:
走出软件作坊》、《悟透JavaScript》、《Head First 设计模式
相关链接:
网站导航:



Web Page Rank Icon