Click to See Complete Forum and Search --> : Splash screens in Java


Qubit
03-29-2002, 01:40 PM
I'm back with another Java question, hope you don't mind.

I want to display a splash screen in my Java app (fyi, a splash screen is typically a little pic that shows up while your application is loading), and for that purpose I have extended JFrame to show an Image.

The code runs along these lines:

public class GSplashScreen extends JWindow {
public GSplashScreen(Image img, JFrame owner) {
// Create a canvas to hold the image,
// and do some resizing
}

public void showScreen() {
show();
toFront();

try {
Thread.getCurrentThread().sleep(3000);
} catch(Exception e) {}
}
}


As soon as I have a JFrame available some time, I construct an instance of this class and call showScreen(). Now, showScreen() calls show() and toFront(), which IMO should be enough to display the splash screen in front of all other currently visible windows. But when I run my app, there are no errors whatsoever, but my splash screen doesn't show up (My main window does, though).

The code I use to display my splash screen:

Toolkit toolkit = Toolkit.getDefaultToolkit();
Image img = toolkit.getImage("ui/einstein.gif");

GravFrame f = new GravFrame("Lensing");
GSplashScreen splash = new GSplashScreen(img, f);

splash.showscreen();
// Carry on initializing
splash.dispose();


(I know, the whole point of a splash screen is to create the top level window while the splash screen is showing (and not the other way round), but I haven't figured that out yet :))

Any ideas about what I left out? I can post more code if you need it, although I think that won't be necessary; the rest of GSplashScreen() is just juggling with the Toolkit to get the splash screen in the middle of the screen.

Qubit
03-29-2002, 01:44 PM
Damn, I've done it again. Just after I posted the previous message, I found a page on google that explained what I was looking for.
http://www.google.be/search?q=Java+splash+screen&ie=UTF8&oe=UTF8&hl=nl&meta=