1 package org.wcb.gui.component;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import javax.swing.JPanel;
22 import javax.swing.JLabel;
23 import javax.swing.SwingUtilities;
24 import javax.swing.SwingConstants;
25 import javax.swing.ImageIcon;
26 import java.awt.BorderLayout;
27 import java.awt.Window;
28 import java.awt.Frame;
29 import java.awt.Toolkit;
30 import java.awt.Dimension;
31 import javax.swing.border.BevelBorder;
32
33
34 public class SplashScreen extends Window {
35
36
37
38
39 private static final long serialVersionUID = 0L;
40 JLabel statusBar;
41
42 public SplashScreen(ImageIcon picture) {
43 super(new Frame());
44 JPanel borderPanel = new JPanel(new BorderLayout());
45 borderPanel.setLayout(new BorderLayout());
46 borderPanel.add(new JLabel(picture), BorderLayout.CENTER);
47 borderPanel.add(statusBar = new JLabel("...", SwingConstants.CENTER), BorderLayout.SOUTH);
48 borderPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
49 add(borderPanel);
50 pack();
51 Dimension windowSize=getSize(), screenSize = Toolkit.getDefaultToolkit().getScreenSize();
52 setBounds((screenSize.width-windowSize.width) / 2, (screenSize.height - windowSize.height) / 2, windowSize.width, windowSize.height);
53 setVisible(true);
54 }
55
56 public void showStatus(String currStatus) {
57 try {
58 SwingUtilities.invokeLater(new UpdateStatus(currStatus));
59 }
60 catch(RuntimeException err) {
61 err.printStackTrace();
62 }
63 }
64
65 public void close() {
66 try {
67 SwingUtilities.invokeLater(new CloseSpashScreen());
68 }
69 catch(RuntimeException e) {
70 e.printStackTrace();
71 }
72 }
73
74 class UpdateStatus implements Runnable {
75 String newStatus;
76 public UpdateStatus(String status) { newStatus = status; }
77 public void run(){ statusBar.setText(newStatus); }
78 }
79
80 class CloseSpashScreen implements Runnable {
81 public void run() {
82 setVisible(false);
83 dispose();
84 }
85 }
86 }