Splash Screen in Java Swing


 

Splash Screen in Java Swing

This Java tutorial section will illustrates you how to implement the splash screen using Java Swing.

This Java tutorial section will illustrates you how to implement the splash screen using Java Swing.

Splash Screen in Java Swing

This Java tutorial chapter explain you how to create and implement the splash screen using Java Swing. The Java Swing splash screen indicates the user that something is happening in the application for the certain amount of time. We have used sleep() method of Thread class to create a swing splash screen in Java. The Java splash screen will get disappeared on its own after the specific amount of time.

Here is the code:


import javax.swing.*;

public class SplashScreen {
	public static void main(String[] arg) {
		JWindow window = new JWindow();
		window.getContentPane().add(
				new JLabel("Loading JFrame...", SwingConstants.CENTER));
		window.setBounds(200, 200, 200, 100);
		window.setVisible(true);
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		window.setVisible(false);
		JFrame frame = new JFrame();
		frame.add(new JLabel("Welcome"));
		frame.setVisible(true);
		frame.setSize(300, 100);
		window.dispose();

	}
}

Ads