The splash window is an introductory screen that is shown to the user, by the time the application is loading on the background. Splash screens cover the entire screen or simply a rectangle near the center of the screen. Usually, a progress bar is also shown along with a splash window which indicates how much loading has been completed and/or how much is remaining.
In this tutorial, I am giving an example of such a splash screen. It also demonstrates the running progress bar. Once the progress bar reaches end/complete, the splash window closes down, and a new window appears which will be the main application window.
Below given code is only for demo purpose to help in building blocks. Please do not refer it for best practices.
1. Splash Window Code
Below is the source code for the splash window. The code is self-explanatory and should be easy to understand. If you still feel the problem, drop a comment.
This code first launches the splash window. Splash the window run the progress bar and then at last open the application window.
importorg.eclipse.swt.widgets.Display;publicclassApplicationLauncher{//Creating static so that can access from splash window code//In production code, use event handlingpublicstaticReportWindow reportWindow;@SuppressWarnings("unused")publicApplicationLauncher(){Display display =newDisplay();
reportWindow =newReportWindow(display);SplashWindow splashWindow =newSplashWindow(display);while((Display.getCurrent().getShells().length !=0)&&!Display.getCurrent().getShells()[0].isDisposed()){if(!display.readAndDispatch()){
display.sleep();}}}publicstaticvoidmain(String[] args){newApplicationLauncher();}}
For reference, these are constants used in the demo program.
A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies.
An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.
Comments