Implementation of Progress Bar as windows

can any one give the implementation of progress bar in java....like in windows i.e calculation of memory, estimating time to copy that whole (folder/file).How to start a thread in Main class to monitor the copying process.Thanks in advance......
[259 byte] By [Vinodbhai@suna] at [2007-11-27 8:57:38]
# 1

here is an example, for a folder copy: (files is the File array resulting from listFiles() method, for example)

boolean folderCopying = true;

int indexOfFileBeingCopied = 0;

int filesArrayLength = files.length;

Thread t = new Thread(){

public void run() {

try { Thread.sleep(1000); } catch (InterruptedException e) {}

while (folderCopying)

bar.setValue( (indexOfFileBeingCopied / filesArrayLength) * 100);

}

};

foreach (File f in files) {

indexOfFileBeingCopied++;

// do the file copy

}

folderCopying = false;

edit: notice that you will prolly have to sleep() after a setValue, to prevent the while loop from taking all ressources

calvino_inda at 2007-7-12 21:22:31 > top of Java-index,Java Essentials,Java Programming...
# 2
except that you're not doing that, you're sleeping once at the beginning of the run() method.And is 'bar' a javax.swing.JProgressBar, or is it a javax.swing.ProgressMonitor?
ejpa at 2007-7-12 21:22:31 > top of Java-index,Java Essentials,Java Programming...
# 3
ejp: the sleep before the loop is made so as to wait a bit, for the main thread to start copyingit's not related to the "edit" below :)
calvino_inda at 2007-7-12 21:22:31 > top of Java-index,Java Essentials,Java Programming...