1 ////////////////////////////////////////////////////////////////////////////////
           2 //
           3 //  @name JWindowDemo.java
           4 //
           5 //  @discription 模擬程序啟動(dòng)窗口
           6 //
           7 //  @author hcm
           8 //
           9 //  @date 2006-12
          10 //
          11 ////////////////////////////////////////////////////////////////////////////////
          12 import javax.swing.*;
          13 import java.awt.*;
          14 import java.net.*;
          15 
          16 //程序啟動(dòng)界面
          17 
          18 public  class JWindowDemo extends JWindow implements Runnable
          19 {
          20     Thread splashThread;                                         //進(jìn)度條更新線程
          21     JProgressBar progress;                                        //進(jìn)度條
          22     
          23     public JWindowDemo()
          24     {
          25         Container container = getContentPane();                     //得到容器
          26         setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));  //設(shè)置光標(biāo)
          27         ImageIcon icon = new ImageIcon (getClass().getResource("login.jpg"));
          28         JLabel label = new JLabel (icon);
          29         container.add("Center",label);                      //增加圖片    
          30         progress = new JProgressBar(1,100);                 //實(shí)例化進(jìn)度條
          31         progress.setStringPainted(true);                    //描繪文字
          32         progress.setString("加載程序中,請(qǐng)稍候");       //設(shè)置顯示文字
          33         progress.setBackground(Color.white);                //設(shè)置背景色
          34         container.add(progress,BorderLayout.SOUTH);         //增加進(jìn)度條到容器上
          35         Dimension screen = getToolkit().getScreenSize();    //得到屏幕尺寸
          36         pack();                                             //窗口適應(yīng)組件尺寸
          37         setLocation((screen.width-getSize().width)/2,(screen.height-getSize().height)/2); //設(shè)置窗口位置
          38     }
          39     
          40     public void start()
          41     {
          42         this.toFront();  //窗口前端顯示
          43         splashThread=new Thread(this);  //實(shí)例化線程
          44         splashThread.start();  //開始運(yùn)行線程
          45     }
          46     
          47     public void run()
          48     {
          49         setVisible(true); //顯示窗口
          50         try
          51         {
          52             for (int i=0;i<100;i++)
          53             {
          54                 Thread.sleep(100); //線程休眠
          55                 progress.setValue(progress.getValue()+1); //設(shè)置進(jìn)度條值
          56             }
          57         }
          58         catch (Exception ex)
          59         {
          60             ex.printStackTrace();
          61         }
          62         dispose(); //釋放窗口
          63         showFrame(); //運(yùn)行主程序
          64     }
          65     
          66     static void showFrame()
          67     {
          68         JFrame frame = new JFrame("程序啟動(dòng)界面演示");                //實(shí)例化JFrame對(duì)象
          69         frame.setSize(300,200);                                      //設(shè)置窗口尺寸
          70         frame.setVisible(true);                                      //窗口可視
          71         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        //關(guān)閉窗口時(shí)退出程序
          72     }
          73     
          74     public static void main(String[] args)
          75     {
          76         JWindowDemo splash = new JWindowDemo();
          77         splash.start();                                              //運(yùn)行啟動(dòng)界面
          78     }
          79 }
          80 

          posted on 2007-02-08 14:00 -274°C 閱讀(378) 評(píng)論(0)  編輯  收藏 所屬分類: JAVA

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊(cè)

          JAVA網(wǎng)站

          關(guān)注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 916109
          • 排名 - 40

          最新評(píng)論

          主站蜘蛛池模板: 淮安市| 灵丘县| 文水县| 杨浦区| 四子王旗| 中卫市| 资兴市| 日喀则市| 大同市| 舒兰市| 东丰县| 曲松县| 鄂温| 同江市| 潮州市| 沛县| 潢川县| 德钦县| 象州县| 江孜县| 沐川县| 云安县| 兰西县| 尚志市| 南和县| 合江县| 长顺县| 宜黄县| 彩票| 乡宁县| 全椒县| 沙河市| 南充市| 开化县| 五常市| 平果县| 浪卡子县| 乌恰县| 兖州市| 三门峡市| 新干县|