Link to home
Start Free TrialLog in
Avatar of JAVAnewbie
JAVAnewbie

asked on

How to create a splash screen for my program?

i have a simple program, and i would like to add splash screen to it to make it look "cool". But i really don't know where/how to start..

public class myprogram extends JFrame{

  public myprogram(){//code}

  public void static main(String[] args){
    myprogram a = new myprogram();
    a.show();
  }
}

where should i add the splashscreen? i'm thinking of creating another JFrame and show it first, and then myprogram, but i failed, the splash screen only appears for 0.000000001 second i guess..

please help
tks
Avatar of pkasturi
pkasturi

Hi,

You can put a progress bar with a fixed time for completion. We have done that for about 3-5 seconds and it also looks as if it is loading some files.

Adding a Progress bar is pretty straight forward.

Prashanth

SOLUTION
Avatar of sciuriware
sciuriware

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
Avatar of JAVAnewbie

ASKER

pkasturi>> can you show me some sample code? it will help me to better understading..
sciuriware>>i visited the link, and get the following code:

class SplashWindow1 extends JWindow
{
    public SplashWindow1(String filename, Frame f)
    {
        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));
        setVisible(true);
        screenSize = null;
        labelSize = null;
    }
}

but i don't understand what is the parameter Frame is use for? how can i add this piece of coding inside my program? please provide some sample code if possible.. tks
Don't use a ProgressBar when there is nothing progressing, don't fool your customer.
Just set a time limit in the right code.
;JOOP!
First create a JFrame, the mainframe of your program, that owns almost all visible things.
Then give that JFrame instance to the code you found.
;JOOP!
is it sth like this?

public class myprogram extends JFrame{

  public myprogram(){//code}

  public void static main(String[] args){
    myprogram a = new myprogram();
    splashscreen sp = new splashscreen("pic.jpg", a);
    sp.show();
  }
}
Yes, does it work?
;JOOP!
maybe a bit better:

public void static main(String[] args){

  myprogram a = new myprogram();

  final SplashScreen splashScreen = new SplashScreen( "pic.jpg", a);
  SwingUtilities.invokeLater( new Runnable()
  {
    public void run()
    {
       splashScreen.setVisible( true );
    }
   } );

  a.setVisible(true);
}

Also class names should start with an uppercase letter, so it should be MyProgram and not myprogram.

ASKER CERTIFIED SOLUTION
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
That will solve your problem :)
>> JLabel l1 = new JLabel(new ImageIcon("Images/Splash1.jpg"));
     
      Just dont forget to insert the image like :

      JLabel l1 = new JLabel(new ImageIcon("YourFolder/YourPicture.jpg"));
 
sciuriware>> the last time i try i doesnt really work, wonder if its the problem of JLabel..

let me try again tonight.
Have you tried my other solution ?