KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > grapheditor > SplashWindow


1 package hero.client.grapheditor;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6
7
8 public class SplashWindow extends JWindow
9     {
10
11     public SplashWindow(/*String filename,*/ java.awt.Frame JavaDoc f,Frame frame /*, int waitTime*/)
12     {
13         
14         super(f);
15         try{
16         String JavaDoc filename="images/open.gif";
17         int waitTime=5;
18         ClassLoader JavaDoc cl = frame.getClass().getClassLoader();
19         JLabel l = new JLabel(new ImageIcon(cl.getResource("images/Splash.gif")));
20         getContentPane().add(l, BorderLayout.CENTER);
21         pack();
22         Dimension screenSize =
23             Toolkit.getDefaultToolkit().getScreenSize();
24         Dimension labelSize = l.getPreferredSize();
25         setLocation(screenSize.width/2 - (labelSize.width/2),
26                 screenSize.height/2 - (labelSize.height/2));
27         addMouseListener(new MouseAdapter()
28             {
29             public void mousePressed(MouseEvent e)
30             {
31                 setVisible(false);
32                 dispose();
33             }
34             });
35 /*
36         final int pause = waitTime;
37         final Runnable closerRunner = new Runnable()
38             {
39             public void run()
40             {
41                 setVisible(false);
42                 dispose();
43             }
44             };
45         Runnable waitRunner = new Runnable()
46             {
47             public void run()
48             {
49                 try
50                 {
51                     Thread.sleep(pause);
52                     SwingUtilities.invokeAndWait(closerRunner);
53                 }
54                 catch(Exception e)
55                 {
56                     e.printStackTrace();
57                     // can catch InvocationTargetException
58                     // can catch InterruptedException
59                 }
60             }
61             };*/

62         setVisible(true);
63         // Thread splashThread = new Thread(waitRunner, "SplashThread");
64
// splashThread.start();
65
}catch(Exception JavaDoc ex){ex.printStackTrace();}
66     }
67 }
68
Popular Tags