進(jìn)度條的使用,我的編程中一直沒有使用到這個(gè)組件,但是應(yīng)該其在程序的啟動(dòng)過程中是非常重要的一個(gè)組件。
           1 ////////////////////////////////////////////////////////////////////////////////////////////
           2 //
           3 //  @name TestJProgressBar.java
           4 //
           5 //  @discription 進(jìn)度條演示程序
           6 //
           7 //  @author hcm
           8 //
           9 //  @date 2006-12
          10 //
          11 /////////////////////////////////////////////////////////////////////////////////////////////
          12 import java.awt.BorderLayout;
          13 import java.awt.Dimension;
          14 import javax.swing.*;
          15 import java.awt.event.*;
          16 import javax.swing.event.ChangeEvent;
          17 import javax.swing.event.ChangeListener;
          18 
          19 public class TestJProgressBar implements ActionListener ,ChangeListener
          20 {
          21     private JPanel panel;
          22     private Timer timer;
          23     private JButton btn;
          24     private JProgressBar pgb;
          25     private JLabel label;
          26     public void init()
          27     {
          28          panel = new JPanel();
          29          btn = new JButton("start");
          30          btn.addActionListener(this);
          31          panel.add (btn,BorderLayout.CENTER);
          32          
          33          timer = new Timer(100,this);
          34          
          35          pgb = new JProgressBar();
          36          pgb.setOrientation (JProgressBar.HORIZONTAL);
          37          pgb.setMaximum (100);
          38          pgb.setMinimum (0);
          39          pgb.setValue (0);
          40          pgb.setStringPainted (true);
          41          pgb.addChangeListener (this);
          42          pgb.setPreferredSize (new Dimension(400,20));
          43          
          44          label = new JLabel("");
          45      
          46         JFrame frame = new JFrame("test");
          47         frame.add (panel,BorderLayout.NORTH);
          48         frame.add (pgb,BorderLayout.CENTER);
          49         frame.add (label,BorderLayout.SOUTH);    
          50         frame.setSize(400,100);
          51         frame.setVisible (true);
          52         frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          53     }
          54     public static void main(String args[])
          55     {
          56         new TestJProgressBar().init ();      
          57     }
          58     public void actionPerformed(ActionEvent e)
          59     {
          60         if(e.getSource ()==btn)
          61         {
          62             timer.start ();
          63             System.out.println ("come here!");
          64         }
          65         if(e.getSource ()==timer)
          66         {
          67             System.out.println ("come here too!");
          68            int value = pgb.getValue () ;
          69            if(value<100)
          70            {
          71                value++;
          72                pgb.setValue (value);
          73            }
          74            if(value ==100)
          75            {
          76                timer.stop ();
          77                pgb.setValue (0);
          78            }
          79             
          80         }
          81     }
          82     public void stateChanged(ChangeEvent e)
          83     { 
          84          System.out.println ("come here too2!");
          85         if(e.getSource ()==pgb)
          86         {
          87              int value = pgb.getValue ();  
          88             label.setText ("以完成:"+value+"%");
          89         }
          90     }
          91 }
          posted on 2007-02-06 16:21 -274°C 閱讀(632) 評(píng)論(1)  編輯  收藏 所屬分類: JAVA


          FeedBack:
          # re: 進(jìn)度條演示程序
          2007-02-06 16:42 | sdasdsdasd
          asdasdasdasd  回復(fù)  更多評(píng)論
            

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊(cè)

          JAVA網(wǎng)站

          關(guān)注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 914107
          • 排名 - 40

          最新評(píng)論

          主站蜘蛛池模板: 仪陇县| 平江县| 海淀区| 铜山县| 太湖县| 玉龙| 江门市| 克东县| 剑阁县| 阿拉善左旗| 尉犁县| 舞钢市| 桃江县| 萨嘎县| 酉阳| 唐海县| 肇东市| 盘锦市| 江门市| 商丘市| 上犹县| 绍兴县| 都昌县| 灵丘县| 盐山县| 山阳县| 济源市| 招远市| 山西省| 武隆县| 屏南县| 察隅县| 于都县| 勃利县| 红河县| 枞阳县| 津市市| 泸州市| 石景山区| 鹰潭市| 乐山市|