Clan x86

Technical (Development, Security, etc.) => General Programming => Tutorials, References, and Examples => Topic started by: Camel on October 31, 2007, 01:09:36 PM

Title: [Java] Tasks with progress bars
Post by: Camel on October 31, 2007, 01:09:36 PM
I've created a couple of classes for managing tasks. When one or more tasks are active, a window will appear with a progress bar showing the status. There are two types of tasks: determinate tasks and indeterminate tasks. The former have a set number of steps; calling advanceProgress() will advance the counter and the progress bar. This type will automatically complete() when it reaches 100%. The latter update by a call to updateProgress(String), which will change the string used in place of the progress percentage.

This is great for monitoring file downloads! Actually, that's the reason I started this. Set each step to 1kB (filesize/1024 steps), and use "kB" for the units.

Sample use:
Code: [Select]
Task ind = TaskManager.createTask("indeterminate task");
Task det = TaskManager.createTask("determinate task", 10, "steps");
for(int i = 0; i < 10; i++) {
ind.updateProgress(Integer.toString(i));
Thread.sleep(100);
det.advanceProgress();
}
ind.complete();

(http://i125.photobucket.com/albums/p70/MrCamel7/bnubot/tasks.png)

http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/util/task/