Solved

How to create a splash screen for my program?

Posted on 2003-11-28
14
380 Views
Last Modified: 2010-05-18
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
Comment
Question by:JAVAnewbie
  • 4
  • 4
  • 4
  • +2
14 Comments
 

Expert Comment

by:pkasturi
ID: 9836309
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
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 25 total points
ID: 9836517
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
 

Author Comment

by:JAVAnewbie
ID: 9836526
pkasturi>> can you show me some sample code? it will help me to better understading..
0
 

Author Comment

by:JAVAnewbie
ID: 9836541
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 9836542
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 9836553
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
 

Author Comment

by:JAVAnewbie
ID: 9836723
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 24

Expert Comment

by:sciuriware
ID: 9836752
Yes, does it work?
;JOOP!
0
 
LVL 1

Expert Comment

by:FesterWim
ID: 9838255
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
 
LVL 15

Accepted Solution

by:
Javatm earned 25 total points
ID: 9840408
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
 
LVL 15

Expert Comment

by:Javatm
ID: 9840410
That will solve your problem :)
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9840417
>> 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
 

Author Comment

by:JAVAnewbie
ID: 9847359
sciuriware>> the last time i try i doesnt really work, wonder if its the problem of JLabel..

let me try again tonight.
0
 
LVL 15

Expert Comment

by:Javatm
ID: 9853633
Have you tried my other solution ?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 3 50
What is the latest versions eclipse neon 2 138
stackato and cloud 4 64
Way to decrease size of apk file 9 40
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now