How to create a Splash Screen

For anyone who's unfamiliar with the term, a splash screen is the graphic that displays the title etc. for a few seconds when you first execute a program.

What's the best way to develop one? I'm using applets for my program.

Could I just create a frame with an image on it and use the Timer class and a TimerEvent for it to display for a couple seconds?

Thanks,

Shawn

[404 byte] By [Basti30] at [2007-9-27 20:17:13]
# 1
Use class Window instead of Frame.Windows do not have title bars, unlike the Frames.
FatihC at 2007-7-7 0:32:57 > top of Java-index,Desktop,Core GUI APIs...
# 2
Excellent. How do I go about displaying the image, and activating the timer?I'm getting a nullPointerException for:myImage = getImage(getDocumentBase(),"R2Logo.jpg");Thanks,Shawn
Basti30 at 2007-7-7 0:32:57 > top of Java-index,Desktop,Core GUI APIs...
# 3

For applications use

Image im = Toolkit.getDefaultToolkit().getImage("image.gif");

But it is easier to use ImageIcons for splash screens.

ImageIcon icon = new ImageIcon("image.gif");

window.getContentPane().add(new JLabel(icon, SwingConstants.CENTER));

window.setSize(x,y);

window.show();

You can finish loading your application and than

window.dispose();

Or if your application does not take any time to load, wait 5 second with

Thread.sleep(5000);

FatihC at 2007-7-7 0:32:57 > top of Java-index,Desktop,Core GUI APIs...
# 4
window.getContentPane().add(new JLabel(icon, SwingConstants.CENTER));This line is not compiling. I've imported javax.swing.* and of course I've created a Window object.Thanks,Shawn
Basti30 at 2007-7-7 0:32:57 > top of Java-index,Desktop,Core GUI APIs...
# 5

try this code

import java.awt.event.*;import javax.swing.*;import java.awt.*;public class SplashScreen extends JWindow {private JPanel main = new JPanel(new BorderLayout());//Constructorpublic SplashScreen(int time) { //ADD EVERYTHING TO MAIN JPANEL!!! getContentPane().add(main); //Show the window pack(); centerScreen(); show(); try {Thread.sleep(time);dispose(); } catch (InterruptedException ie) {}}//Simple method to center in screenprivate void centerScreen() { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((d.getWidth() - getWidth()) / 2); int y = (int) ((d.getHeight() - getHeight()) / 2); setLocation(x, y);}}

It uses a JWindow so that you do not see any title bar etc. You use this just like a JFrame.

Example:

In you main program, BEFORE YOU DO A pack() show() (if a JFrame) do this:

SplashScreen splash = new SplashScreen(time in milliseconds);

Hope this helps

bengster at 2007-7-7 0:32:57 > top of Java-index,Desktop,Core GUI APIs...
# 6

sorry this maybe clearer

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

public class SplashScreen extends JWindow

{

private JPanel main = new JPanel(new BorderLayout());

//Constructor

public SplashScreen(int time)

{

//ADD EVERYTHING TO MAIN JPANEL!!!

getContentPane().add(main);

//Show the window

pack();

centerScreen();

show();

try

{

Thread.sleep(time);

dispose();

} catch (InterruptedException ie) {}

}

//Simple method to center in screen

private void centerScreen()

{

Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

int x = (int) ((d.getWidth() - getWidth()) / 2);

int y = (int) ((d.getHeight() - getHeight()) / 2);

setLocation(x, y);

}

}

It uses a JWindow so that you do not see any title bar etc. You use this just like a JFrame.

Example:

In you main program, BEFORE YOU DO A pack() show() (if a JFrame) do this:

SplashScreen splash = new SplashScreen(time in milliseconds);

Hope this helps

bengster at 2007-7-7 0:32:57 > top of Java-index,Desktop,Core GUI APIs...
# 7
My code examples above were for JWindow not for Window.*FatihC*
FatihC at 2007-7-7 0:32:57 > top of Java-index,Desktop,Core GUI APIs...
# 8

Thats all fine. But what If I want a JLabel below the image that says "Loading..." and the dots should go on increasing and say, after 20 dots are displayed, then the dots should start back from one ? I am having major refreshing problems. I am using the repaint method, but the label just doesn't get refreshed.

FarhadT at 2007-7-7 0:32:57 > top of Java-index,Desktop,Core GUI APIs...
# 9

I having a problem displaying the splash screen but I am doing things a little differently...

I have a login JDialog window that comes up to log someone in to a database. After the login is successful, I create a splash screen (JWindow) and dispose of the login screen. My splash screen never shows up. Basically I am processing a database query and creating a new JFrame from it and want a splash screen saying "Loading...". After the JFrame is complete, I dispose of the splash screen. Please tell me why the splash screen never shows up and give me a better solution.

Thanks.

> sorry this maybe clearer

>

> import java.awt.event.*;

> import javax.swing.*;

> import java.awt.*;

>

> public class SplashScreen extends JWindow

> {

> private JPanel main = new JPanel(new

> new BorderLayout());

>

>//Constructor

>public SplashScreen(int time)

>{

>//ADD EVERYTHING TO MAIN JPANEL!!!

>getContentPane().add(main);

>

>//Show the window

>pack();

>centerScreen();

>show();

>try

>{

> Thread.sleep(time);

> dispose();

>} catch (InterruptedException ie) {}

> }

> //Simple method to center in screen

> private void centerScreen()

> {

> Dimension d =

> = Toolkit.getDefaultToolkit().getScreenSize();

>int x = (int) ((d.getWidth() - getWidth()) / 2);

>int y = (int) ((d.getHeight() - getHeight()) / 2);

>setLocation(x, y);

> }

>

> }

>

> It uses a JWindow so that you do not see any title bar

> etc. You use this just like a JFrame.

>

> Example:

>

> In you main program, BEFORE YOU DO A pack() show() (if

> a JFrame) do this:

>

> SplashScreen splash = new SplashScreen(time in

> milliseconds);

>

> Hope this helps

polandma at 2007-7-7 0:32:57 > top of Java-index,Desktop,Core GUI APIs...