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
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