3 //import javax.swing.*;
5 import java.awt.event.*;
10 * <p>Description: </p>
11 * <p>Copyright: Copyright (c) 2003</p>
13 * @author not attributable
17 public class SplashScreen extends Window {
18 private Image splashImage;
19 private boolean paintCalled = false;
21 public SplashScreen(Frame owner) {
23 URL imageURL = SplashScreen.class.getResource("/images/splash-2.1beta.png");
24 splashImage = Toolkit.getDefaultToolkit().createImage(imageURL);
27 MediaTracker mt = new MediaTracker(this);
28 mt.addImage(splashImage,0);
31 } catch(InterruptedException ie) {}
34 // Center the window on the screen.
35 int imgWidth = splashImage.getWidth(this);
36 int imgHeight = splashImage.getHeight(this);
38 setSize(imgWidth, imgHeight);
39 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
41 (screenDim.width - imgWidth) / 2,
42 (screenDim.height - imgHeight) / 2
49 * Updates the display area of the window.
51 public void update(Graphics g) {
52 // Note: Since the paint method is going to draw an
53 // image that covers the complete area of the component we
54 // do not fill the component with its background color
55 // here. This avoids flickering.
57 g.setColor(getForeground());
61 * Paints the image on the window.
64 public void paint(Graphics g) {
65 g.drawImage(splashImage, 0, 0, this);
67 // Notify method splash that the window
71 synchronized (this) { notifyAll(); }
76 * Constructs and displays a SplashWindow.<p>
77 * This method is useful for startup splashs.
78 * Dispose the returned frame to get rid of the splash window.<p>
80 * @param splashImage The image to be displayed.
81 * @return Returns the frame that owns the SplashWindow.
84 public static Frame splash() {
85 Frame f = new Frame();
86 SplashScreen w = new SplashScreen(f);
92 // Note: To make sure the user gets a chance to see the
93 // splash window we wait until its paint method has been
94 // called at least once by the AWT event dispatcher thread.
96 // sebwills adds: However, just in case the paint method never gets called
97 // (e.g. if the splashscreen is completely obscured by an 'always on top'
98 // window of some other application), we time-out after 5 seconds.
99 if (! EventQueue.isDispatchThread()) {
101 if (! w.paintCalled) {
104 } catch (InterruptedException e) {}