模拟程序启动


<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->  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( " 加载程序中,请稍候dot.gifdot.gif " );        // 设置显示文字
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 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值