Ant Before the Horse
You will use Apache Ant to build the application. So if you don't have it already, download Apache Ant
from the Apache Web site and install it on your computer.
A check of the Ant Java version using the following Ant property reveals an incorrect Java version:
This is because Ant's built-in
ant.java.version system property is designed to hold only 1.1, 1.2, 1.3, 1.4, and 1.5 values. The Ant development team will likely update this property soon to include 1.6, but you are playing with bleeding edge technology in this case.
For the persnickety, running Ant with
–debug will show the following, which means Ant in fact is using a 1.6 JRE:
Detected Java version: 1.5 in: C:\Program Files\Java\jdk1.6.0\jre
Trot Before You Gallop
Next, set up your development environment. The simplest way to do that is to download the accompanying code
for this article and extract its contents. If you extract the ZIP file on your C:\ drive, you should see the following file and directories:
You will use build.xml, the Ant build file, to copy, compile, build, package, and run the GoMustang application. It contains the following key Ant targets:
The [init] target sets up the folder structure and copies files to the build folder; [compile] does the compilation, while [dist] creates a jar with a Manifest file (more on this later). The [run] target comes in handy for launching your application, while [clean] is useful if you want to start with a clean slate and delete all the files and directories created by any of the Ant tasks.
The src directory contains three files: GoMustang.java (the source code file) and two GIF files (gomustang-splash.gif is used as a splash screen, and gomustang.gif is used as an icon in the system tray).
Now that you understand the basics, you can jump right into creating a splash screen for your application.
The Splash Screen
Splash screens for desktop-based applications have always played a vital role in the applications' perceived start-up response times. A sharp splash screen can keep the user engaged at the start of the application by displaying marketing blurbs, legal and statutory fine print, professional images, etc. Meanwhile, it provides the application cycles to load the required libraries.
Splash screens for Java-based applications have always been a challenge because Java applications do not get control until the JVM has started and all the required JRE and application libraries have been loaded. By the time a Java application gets control of the thread, it's too late to show a splash screen.
Java SE 6 allows an application to show a splash screen even before the JVM starts. This functionality is built into the Java application launcher, which can display an image in an undecorated window. It allows GIF, PNG, or JPEG images, with transparency, translucency, and animation. Furthermore, it comes bundled with the SplashScreen class, which allows manipulation of the splash screen once an application gains control of the thread.
You can launch a splash screen in the following two ways:
- Specify a special SplashScreen-Image attribute in a JAR's Manifest file
- Use a command line -splash parameter