Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

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
0
JAVAnewbie
Asked:
JAVAnewbie
  • 4
  • 4
  • 4
  • +2
2 Solutions
 
pkasturiCommented:
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

0
 
sciuriwareCommented:
Create a JWindow and start off tghere in.
A complete course in writing a splash screen is found in:
http://www.javaworld.net/javaworld/javatips/jw-javatip104.html 
Success!

;JOOP!
0
 
JAVAnewbieAuthor Commented:
pkasturi>> can you show me some sample code? it will help me to better understading..
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
JAVAnewbieAuthor Commented:
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
0
 
sciuriwareCommented:
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!
0
 
sciuriwareCommented:
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!
0
 
JAVAnewbieAuthor Commented:
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();
  }
}
0
 
sciuriwareCommented:
Yes, does it work?
;JOOP!
0
 
FesterWimCommented:
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.

0
 
JavatmCommented:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Splash extends JWindow {

private int waitTime;

 public Splash()
  {

// Insert your picture here :

  JLabel l1 = new JLabel(new ImageIcon("Images/Splash1.jpg"));
  JLabel l2 = new JLabel(new ImageIcon("Images/Splash2.gif"));  

  getContentPane().add(l1, BorderLayout.CENTER);
  getContentPane().add(l2, BorderLayout.SOUTH);
  getContentPane().setBackground(Color.black);
  pack();

  Dimension sd = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

  setLocation(sd.width / 2 - 310 / 2,
  sd.height / 2 - 265 / 2);

  setSize(310, 265);
  setVisible(true);
   }

  public static void main( String args[] )
   {
   Splash app = new Splash();
   }  
}
0
 
JavatmCommented:
That will solve your problem :)
0
 
JavatmCommented:
>> 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"));
 
0
 
JAVAnewbieAuthor Commented:
sciuriware>> the last time i try i doesnt really work, wonder if its the problem of JLabel..

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now