Preface:
Almost all modern applications have a splash screen. Typically splash screens are used for the following purposes:
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. The figure below represents an example of the Java application splash screen developed as an animated gif file.
The SplashScreen class is used to close the splash screen, change the splash-screen image, obtain the image position or size, and paint in the splash screen. An application cannot create an instance of this class. Only a single instance created within this class can exist, and this instance can be obtained using the getSplashScreen()static method. If the application has not created the splash screen at startup through the command-line or manifest-file option, the getSplashScreen method returns null.
Typically, a developer wants to keep the splash-screen image on the screen and display something over the image. The splash-screen window has an overlay surface with an alpha channel, and this surface can be accessed with a traditional Graphics2D interface.
The following code snippet shows how to obtain a SplashScreen object, then how to create a graphics context with the createGraphics() method:
- ...
- final SplashScreen splash = SplashScreen.getSplashScreen();
- if (splash == null) {
- System.out.println("SplashScreen.getSplashScreen() returned null");
- return;
- }
- Graphics2D g = splash.createGraphics();
- if (g == null) {
- System.out.println("g is null");
- return;
- }
- ...
How to Use the Command-Line Argument to Display a Splash Screen
To display a splash screen from the command line use the -splash: command-line argument. This argument is a Java application launcher option that displays a splash screen: java -splash:<file name> <class name>
Try this:
How to Use a JAR File to Display Splash Screen
If your application is packaged in a JAR file, you can use the SplashScreen-Image option in a manifest file to show a splash screen. Place the image in the JAR file and specify the path in the option as follows:
- Manifest-Version: 1.0
- Main-Class: <class name>
- SplashScreen-Image: <image name>
Supplement:
* Java Gossip: 製作 Executable JAR
沒有留言:
張貼留言