paXoftwer JSplashScreen

This splash screen package allows to display an image picture during some initialization processes on the application's startup.




This splash screen package allows to display an image picture during some initialization processes on the application's startup. After the instanciation of the SplashScreen class it starts showing of the picture.

You can pass following values to the constructor:

  1. Time value in milli-seconds
  2. ImageIcon object which contains the picture
  3. (Optional: A loading progress indicator)

Time value in milli-seconds: This parameter determines the minimum of time the splash screen will be shown.

In other words, if you passed 3000 milli-seconds (T2), but your application does only need 1500 milli-seconds (T1) for initializing of resources, the splash screen will anyway remain the last 1500 milli-seconds (T delta) until the total remaining time of 3000 (T2) has expired (see drawing).

You can say:

ImageIcon object: This refers to the class: javax.swing.ImageIcon
For example, you can get one picture file from your application resource path and assign it to such object:

ImageIcon pic = new ImageIcon(SplashScreen.class.getResource("graphics/ani01.gif"));

After doing this, you just pass pic to SplashScreen's constructor.

Loading progress indicator: This may be a proper Swing/AWT component to show continiously concrete loading progress of any resources. Later you can access it via getProgressComponent() to change its appearance. Imaginable components are JProgressBar, JLabel etc.

Caution: In all cases, you have to position the component by setting the bounds with help of Component.setBounds(int, int, int, int).

General approach

These steps are necessary:
  1. Create an instance (initialized with the splash screen picture) of javax.swing.ImageIcon.
  2. Optionally, also create a progress indicator object, inclusively setting of its bounds.
  3. Create an instance of SplashScreen and pass all necessary values to the constructor. This step should be the first thing what your application is doing at startup, because the splash screen will be directly shown after its instanciation.
  4. Let your application start and initialize the needed resources.
  5. If everything was loaded, send to the SplashScreen object the termination signal. If you don't do it, it won't fade away.

Programming example

Following code snippet initializes the JSplashScreen with a simple GIF animation file and starts showing it for at least 3 seconds. Furthermore, we are adding a JProgressBar, inclusively refreshing its progress state during the simulated computing process. The computing process equals a simple Thread.sleep(long) and lasts for 6 seconds (3 seconds more than the minimum showing time). The expected behaviour of the splash screen is to remain for 6 seconds: