Solved

How to create a splash screen for my program?

Posted on 2003-11-28
14
379 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert ArrayList of custom objects to JSON 4 53
scoresSpecial  challenge 13 42
json example 39 115
Eclipse Neon and jdk 1.8.0 11 69
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now