Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a splash screen for GUI?

Hi there I'm new to GUIs in Java and was trying to make a splash screen or an image appear for 3 seconds. Then after that it it will go onto my main program. Does anyone have an ideas how to do this or can link me to any tutorials?

So far I have done this but not sure where to go from here.

public static void main(String[] args)
{
    splashInit();           // initialize splash overlay drawing parameters
    appInit();              // simulate what an application would do 
}
like image 939
Ali Issa Avatar asked Apr 21 '13 18:04

Ali Issa


2 Answers

Simplest one , is to create JFrame and add your screen on it then use Thread.Sleep(long millies)

Try this code:

JWindow window = new JWindow();
window.getContentPane().add(
    new JLabel("", new ImageIcon(new URL("http://docs.oracle.com/javase/tutorial/uiswing/examples/misc/SplashDemoProject/src/misc/images/splash.gif")), SwingConstants.CENTER));
window.setBounds(500, 150, 300, 200);
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();

Or you can Create a Splash Screen by using SplashScreen class

like image 75
Alya'a Gamal Avatar answered Oct 23 '22 08:10

Alya'a Gamal


See also How to Create a Splash Screen for the AWT based splash functionality.

splash image

like image 31
Andrew Thompson Avatar answered Oct 23 '22 08:10

Andrew Thompson