Tuesday, July 26, 2011

Splash Screen In Java

Splash screens are simple graphics which load quickly upon startup, and assure the user that the application is loading promptly. The SplashScreen class was added to JSE 6, and should be used if available.

If JSE 6 is not available, then the following technique is provided as an alternative.

Various policies for controlling the appearance and disappearance of the splash screen are possible. Here, the splash screen disappears when a main window has finished loading.

This example is also of interest since it demonstrates clearly that the launch thread is unusual - it is distinct from the event dispatch thread, where most of the work of a Swing application takes place :

upon launch, the launch thread shows a splash screen, which activates the event dispatch thread
once the splash screen is showing (or, more precisely, is "realized"), the launch thread acts as a "worker thread", and can only close the splash screen indirectly, using EventQueue.invokeLater to properly inject an event into the event dispatch thread

For sample code drop a comment

No comments: