Pradeep's Blog

Google

Monday, May 08, 2006

Progress bar for your application:

Majority of applications need progress bars to show the progress of time consuming operations. Most people have common questions like: Do I need Threads? How to integrate progress bar into my application? This blog answers these common questions.

As for the first question, yes, you need Threads. Without Threads you cannot multitask, meaning you cannot update the progress bar while your time consuming task is running.

The next question is how to integrate progress bar using Threads? Let’s assume that you have a time consuming task in class A. In order to use thread make this class extend Thread. Put the time consuming task in the run method (This enables the task to run in a separate thread by calling the start () method with an object of class A). In this class have an integer variable that you increment according to the progress of your task.

Most applications make the progress bar to popup in a new window. So have it in another class that extends JDialog or JFrame. Add a timer to this class with an action listener added to it. In the action performed method get the integer from class A and set the progress bar’s value to it.

Now that we have both the classes, you can start the task & the progress bar by calling the start () function in class A, followed immediately by a function that starts the timer in the progress bar class.

2 Comments:

  • Nice idea with this site its better than most of the rubbish I come across.
    »

    By Anonymous Anonymous, at 1:38 PM  

  • Really amazing! Useful information. All the best.
    »

    By Anonymous Anonymous, at 7:53 PM  

Post a Comment

<< Home