Solved

Progress Bar

Posted on 2004-09-03
17
320 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 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

751 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