A Java splash screen with a progress bar (Part 3)

<< Back to "Java splash screen with progress bar, part 2"

Closing/destroying the splash screen

When you finish "starting up" your application you'll want to remove the splash screen and replace it with your application windows, presumably a Java JFrame Because my SplashScreen class is a simple JWindow you can achieve this effect by making the window not visible, as I do in the splashScreenDestruct method shown below:

private void splashScreenDestruct() {
  screen = null;

I also set the screen reference to null. This isn't required, but for the purposes of this article, I thought it might clarify my intent.

My Java splash screen "driver" class

That finishes my discussion of the "driver" class that I used to build and test my SplashScreen class. For completeness, here is a listing of the full source code of this class.

package com.devdaily.splashscreen;

import javax.swing.UIManager;
import javax.swing.ImageIcon;

public class SplashScreenMain {

  SplashScreen screen;

  public SplashScreenMain() {
    // initialize the splash screen
    // do something here to simulate the program doing something that
    // is time consuming
    for (int i = 0; i <= 100; i++)
      for (long j=0; j<50000; ++j)
        String poop = " " + (j + i);
      // run either of these two -- not both
      screen.setProgress("Yo " + i, i);  // progress bar with a message
      //screen.setProgress(i);           // progress bar with no message

  private void splashScreenDestruct() {

  private void splashScreenInit() {
    ImageIcon myImage = new ImageIcon(com.devdaily.splashscreen.SplashScreenMain.class.getResource("SplashImage.gif"));
    screen = new SplashScreen(myImage);

  public static void main(String[] args)
    try {
    catch (Exception e) {
    new SplashScreenMain();


Java Splash Screen source code

You can also download the SplashScreenMain.java source code.


<< Previous: "Java splash screen with progress bar, part 2"

Next: Java splash screen with progress bar, part 4 >>