Solved

Progress Bar

Posted on 2004-09-03
17
321 Views
Last Modified: 2010-03-31
I have main method which contains the follwoing code
       
         
         if (loginIns.isValidUser()) {
            //Instantiate the Splash Screen after successfull login
            SplashScreen s = new SplashScreen(Image.getIcon("icon"), new Frame());

            logger.info("Validated");
            AD.getInstance();
            A.initData();
            //initialises all the PanelControllers

            PFactory.getInstance().initialise();
            Fer.getInstance();
//      .. number of other things are instantiated

            UserInterfaceManager uiManager = new UserInterfaceManager();
            Util.setAppFrame(uiManager);
            uiManager.initialize();

            // close Splash Screen
             s.closeSplashScreen();
        }

Under the Splash Screen i want to display a progress bar which automatically closes when the splash screen closes (that is the application loads).
How can i do this?
plz help
0
Comment
Question by:thomas908
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +3
17 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 11971642
Should the progress bar not close automatically when it finishes?
0
 
LVL 8

Author Comment

by:thomas908
ID: 11971688
>> Should the progress bar not close automatically when it finishes?
Yes it should
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11971757
it will close once u close the window.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:expertmb
ID: 11971783
if you are adding the progress bar to splashscreen, when the splash screen closes, progressbar will also close.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11971784
So what's the problem? You do not know how to create a JProgressBar?
0
 
LVL 6

Expert Comment

by:expertmb
ID: 11971793
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 11971824
This should help: http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html

Note that if you start any processes from a GUI (i.e. via an actionListener, etc.) during the time that the progress bar is monitoring, they'll need to be started in a separate thread.
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 11971830
Beaten... :(
0
 
LVL 8

Author Comment

by:thomas908
ID: 11972023
>> if you are adding the progress bar to splashscreen, when the splash screen closes, progressbar will also close.
How to add progress bar to splash screen?
splash screen is a image
:(
0
 
LVL 35

Expert Comment

by:girionis
ID: 11972047
What is this class: SplashScreen

You should add the progress bar in there.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11972376
>> splash screen is a image
You mean your splash screen mainly *contains* an image.
It's probably a JPanel/JDialog in which you can add your progress bar.
(Probably BorderLayout, with the image in the CENTER and the progress bar in the SOUTH)
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 11972589
This is a modified example from javaworld (http://www.javaworld.com/javaworld/javatips/jw-javatip104.html) that is working. Modify it to fit your own needs:

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

class SplashWindow3 extends JWindow
{
      public static void main(String [] arguments)
      {
            new SplashWindow3("figure4.gif", new JFrame(), 10000);
      }
      
    public SplashWindow3(String filename, JFrame f, int waitTime)
    {
        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));

        addMouseListener(new MouseAdapter()
            {
                public void mousePressed(MouseEvent e)
                {
                    setVisible(false);
                    dispose();
                }
            });

                  
            final JProgressBar progress = new JProgressBar();
            progress.setIndeterminate(true);
            progress.setSize(10, 10);
        progress.setLocation(0, 10);
        getContentPane().add(progress, BorderLayout.NORTH);
            

        final int pause = waitTime;
        final Runnable closerRunner = new Runnable()
            {
                public void run()
                {
                    setVisible(false);
                    dispose();
                }
            };
        Runnable waitRunner = new Runnable()
            {
                public void run()
                {
                    try
                        {
                            Thread.sleep(pause);
                            SwingUtilities.invokeAndWait(closerRunner);
                        }
                    catch(Exception e)
                        {
                            e.printStackTrace();
                            // can catch InvocationTargetException
                            // can catch InterruptedException
                        }
                }
            };
        setVisible(true);
        Thread splashThread = new Thread(waitRunner, "SplashThread");
        splashThread.start();
    }
}
0
 
LVL 92

Expert Comment

by:objects
ID: 11977466
> How to add progress bar to splash screen?
> splash screen is a image

Use a JLabel to display your image, and either add your progress bar to the panel containing the label or to the label directly depending on where you want it to appear.

0
 
LVL 8

Author Comment

by:thomas908
ID: 11978947
Thanks You so much
0
 
LVL 8

Author Comment

by:thomas908
ID: 11978949
sorry typo ;)
*Thank You so much
0
 
LVL 35

Expert Comment

by:girionis
ID: 11980952
Thank you for accepting :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

615 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