Link to home
Start Free TrialLog in
Avatar of lotus03
lotus03

asked on

How to display Splash Screen in longer time?

How to display a splash screen in a longer time? such as in 10 seconds time.... Thank you!

Code:
*********************************
 public static void main( String[] args )
{
    String baseDir="";
    if(args.length>0){ baseDir=args[0]; }
    splashScreen = new SplashScreen(10);
    splashScreen.dispose();
    Bella bella= new bella();
}
Avatar of yongsing
yongsing

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Pretty Fast Guys;

Here are my share :

class SplashWindow3 extends JWindow
{
    public SplashWindow3(String filename, Frame f, int waitTime)
    {
        super(f);
        JLabel l = new JLabel(new ImageIcon(filename));
        getContentPane().add(l, BorderLayout.CENTER);
        pack();
        Dimension screenSize =
          Toolkit.getDefaultToolkit().getScreenSize();
        Dimension labelSize = l.getPreferredSize();
        setLocation(screenSize.width/2 - (labelSize.width/2),
                    screenSize.height/2 - (labelSize.height/2));
        addMouseListener(new MouseAdapter()
            {
                public void mousePressed(MouseEvent e)
                {
                    setVisible(false);
                    dispose();
                }
            });
        final int pause = waitTime;
        final Runnable closerRunner = new Runnable()
            {
                public void run()
                {
                    setVisible(false);
                    dispose();
                }
            };
        Runnable waitRunner = new Runnable()
            {
                public void run()
                {
                    try
                        {
                            Thread.sleep(pause);
                            SwingUtilities.invokeAndWait(closerRunner);
                        }
                    catch(Exception e)
                        {
                            e.printStackTrace();
                            // can catch InvocationTargetException
                            // can catch InterruptedException
                        }
                }
            };
        setVisible(true);
        Thread splashThread = new Thread(waitRunner, "SplashThread");
        splashThread.start();
    }
}

>> Thread.sleep(pause);

Give a interval something like 1000

Hope it helps . . .
Javatm
Javatm, you copied from the article that I gave!
I dont think so, I've researched it here on EE,
before you post it I already seen it. So I added it.
Sorry if I paste it friend :)