How to Create a Splash Screen
Java Foundation Classes, both Swing and Abstract Windowing Toolkit (AWT), enable a developer to create splash screens in Java technology applications. However, because the main purpose of a splash screen is to provide the user with feedback about the application's startup, the delay between the application's startup and the moment when the splash screen pops up should be minimal. Before the splash screen can pop up, the application has to load and initialize the Java™ Virtual Machine (JVM), AWT, Swing, and sometimes application-dependent libraries as well. The resulting delay of several seconds has made the use of a Java™ technology-based splash screen less than desirable.
Fortunately, Java™ SE 6 provides a solution that allows the application to display the splash screen much earlier, even before the virtual machine starts. A Java application launcher is able to decode an image and display it in a simple non-decorated window.
The splash screen can display any gif, png, or jpeg image, with transparency, translucency, and animation.
Try this:
-
Compile the
file.SplashDemo.java -
Save the
image in thesplash.gifimagesdirectory. -
Run the application from the command line with the following arguments:
java -splash:images/splash.gif SplashDemo
-
Wait until the splash screen has been completely displayed.
-
The application window appears. To close the window choose File|Exit from the pop-up menu or click the X.
-
Change the splash screen name to a non-existent image, for example,
nnn.gif. Run the application as follows:java -splash:images/nnn.gif SplashDemo
-
You will see the following output string:
SplashScreen.getSplashScreen() returned null