Solved

How to create a splash screen for my program?

Posted on 2003-11-28
14
382 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
factorial example 4 47
eclipse apache tomcat admin console 52 121
null output 3 35
Java: How do I open the default windows program for a given file type 3 39
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

809 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