Solved

Progress Bar

Posted on 2004-09-03
17
319 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
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
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 6

Expert Comment

by:expertmb
ID: 11971817
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle 11g 23 107
eclipse buid path vs tomcat lib path 10 34
ejb example issues 3 28
Html Table Looping (part 2) 5 27
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
This video teaches viewers about errors in exception handling.

828 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