Share on Google+Share on Google+

Splash Screen in Java Swing

Advertisement
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();

	}
}

Advertisements

Posted on: October 31, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.