splash screen

Hello All:

I've decided to add a splash screen to a GUI app that I'm building.

However I'd like it to be Swing related if possible as opposed to AWT.

Does anyone know where or rather how I can start this.

I'm looking for two extremes of splash screens: a millisecond -- (dare I say) screen and a more conventional welcoming splash screen.

Any pointers in the right direction would be greatly appreciated.

[461 byte] By [elsteamola] at [2007-9-26 1:33:41]
# 1
I would try extending JWindow and have your SplashScreen class implement Runnable.
brwelling at 2007-6-29 2:15:48 > top of Java-index,Archived Forums,Swing...
# 2

Here some code, that can be used whenever a time consuming process is started:

import javax.swing.*;

import javax.swing.border.*;

import java.awt.*;

/**

* creates a splashscreen that runs a time consuming process

* in a separate thread, so that the splashscreen itself can be visualized properly

*/

abstract class SplashScreen extends JWindow

{

/**

* Constructor for a SplashScreen, that is located at the middle

* of the screen

* Shows a centered image above a message text

*

* Example:

* SplashScreen splash = new SplashScreen(..., ..., ...)

* {

*public void timeConsuming()

*{

*//insert the time consuming code here

*}

* };

* splash.start();

*

* @param component Parent component, the SplashScreen is positioned relative to it

* @param text Text that is shown at the SplashScreen

* @param image Image that is shown at the SplashScreen

*/

public SplashScreen(Component component, String text, String image)

{

JPanel contentPane = new JPanel();

contentPane.setLayout(new BorderLayout());

Border bd1 = BorderFactory.createBevelBorder(BevelBorder.RAISED);

Border bd2 = BorderFactory.createEtchedBorder();

Border bd3 = BorderFactory.createCompoundBorder(bd1, bd2);

((JPanel)contentPane).setBorder(bd3);

ImageIcon icon = new ImageIcon(getClass().getResource(image));

contentPane.add("Center", new JLabel(icon, JLabel.CENTER));

contentPane.add("South", new JLabel(text, JLabel.CENTER));

setContentPane(contentPane);

setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

pack();

int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;

int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;

setLocation(screenWidth / 2 - getSize().width / 2, screenHeight / 2 - getSize().height / 2);

}

/**

* create an object of SplashScreen and override this method to include

* the code that is needed to be splashscreened

*/

public abstract void timeConsuming();

/**

* sets the splashscreen visible, starts the time consuming code

* and than disposes the splashscreen

*/

public void start()

{

Thread t = new Thread()

{

public void run()

{

Runnable r = new Runnable()

{

public void run()

{

timeConsuming();

dispose();

}

};

setVisible(true);

SwingUtilities.invokeLater(r);

}

};

t.start();

}

}

thoralf001 at 2007-6-29 2:15:48 > top of Java-index,Archived Forums,Swing...