How can I use a Splash Screen in a Java Application ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Charles_Garcia
Posted On:   Saturday, November 23, 2002 04:10 PM

Hi.!!


I would like to know how I can implement a Splash Screen in a Java application, I mean , show an image while mi applications is loading.


thanks.

Charles G.

Re: How can I use a Splash Screen in a Java Application ?

Posted By:   Anonymous  
Posted On:   Sunday, November 24, 2002 10:38 AM

Use a JWindow. Try something like this (1.4):


import java.awt.BorderLayout;
import java.net.URL;
import javax.swing.*;

public class SplashWindow extends JWindow {

public SplashWindow(String imageFile) {
URL imageURL = getClass().getResource(imageFile);
ImageIcon icon = new ImageIcon(imageURL);
// Image as a JLabel
getContentPane().add(new JLabel(icon),BorderLayout.CENTER);
pack();
setLocationRelativeTo(null); // center
toFront();
setVisible(true);
}
}


And...


SplashWindow splash = new SplashWindow("/splash.gif");
// Your code here...
splash.dispose();


HTH,
Guido
About | Sitemap | Contact