1 ////////////////////////////////////////////////////////////////////////////////
 2 //
 3 //  @name JWindowDemo.java
 4 //
 5 //  @discription 模拟程序启动窗口
 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 //程序启动界面
17 
18 public  class JWindowDemo extends JWindow implements Runnable
19 {
20     Thread splashThread;                                         //进度条更新线程
21     JProgressBar progress;                                        //进度条
22     
23     public JWindowDemo()
24     {
25         Container container = getContentPane();                     //得到容器
26         setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));  //设置光标
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);                 //实例化进度条
31         progress.setStringPainted(true);                    //描绘文字
32         progress.setString("加载程序中,请稍候");       //设置显示文字
33         progress.setBackground(Color.white);                //设置背景色
34         container.add(progress,BorderLayout.SOUTH);         //增加进度条到容器上
35         Dimension screen = getToolkit().getScreenSize();    //得到屏幕尺寸
36         pack();                                             //窗口适应组件尺寸
37         setLocation((screen.width-getSize().width)/2,(screen.height-getSize().height)/2); //设置窗口位置
38     }
39     
40     public void start()
41     {
42         this.toFront();  //窗口前端显示
43         splashThread=new Thread(this);  //实例化线程
44         splashThread.start();  //开始运行线程
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); //设置进度条值
56             }
57         }
58         catch (Exception ex)
59         {
60             ex.printStackTrace();
61         }
62         dispose(); //释放窗口
63         showFrame(); //运行主程序
64     }
65     
66     static void showFrame()
67     {
68         JFrame frame = new JFrame("程序启动界面演示");                //实例化JFrame对象
69         frame.setSize(300,200);                                      //设置窗口尺寸
70         frame.setVisible(true);                                      //窗口可视
71         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        //关闭窗口时退出程序
72     }
73     
74     public static void main(String[] args)
75     {
76         JWindowDemo splash = new JWindowDemo();
77         splash.start();                                              //运行启动界面
78     }
79 }
80 

posted on 2007-02-08 14:00 -274°C 阅读(357) 评论(0)  编辑  收藏 所属分类: JAVA

只有注册用户登录后才能发表评论。


网站导航:
 

常用链接

留言簿(21)

随笔分类(265)

随笔档案(242)

相册

JAVA网站

关注的Blog

搜索

  •  

积分与排名

  • 积分 - 909100
  • 排名 - 40

最新评论