Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.3k views
in General by (440 points)
Hi,

I got the progress indicator to perform as needed on the commandline.
Now my question is how to I take the data and update a swing progress bar / monitor?

I have the progressmonitor class as follows:
import com.enterprisedt.net.ftp.*;

public class ProgressMonitor implements FTPProgressMonitor {
public static long MyNum = 0;

public void bytesTransferred(long count) {
float answer = ( ( (int)count / (int)MyNum )+1 );
System.out.println(count + " : " + answer );
}
}
-----
In the main program, the gui is drawn, and the ftp portion is executed when a button is clicked. The progress bar is already drawn and awaiting use. The progress bar is a publically accessible JProgressbar, called progressBar.

// MySize was defined earlier as a long int.
MySize = ftp.size(targetFile);
//here a new ftpprogressmonitor is created from the classfile
// ProgressMonitor.class (which appears below...)
FTPProgressMonitor monitor = new ProgressMonitor();
// In the Progress Monitor class is the MyNum variable. we set it here.
ProgressMonitor.MyNum = MySize;
//Monitor is setup.
ftp.setProgressMonitor(monitor, 1024);
// Transfer type is set.
ftp.setType(FTPTransferType.BINARY);
// Download the file
ftp.get(tmpOutput, targetFile);

So, How would I get the variable 'answer' from the progressmonitor class back into the main program in order to update the progess bar?

2 Answers

0 votes
by (156k points)
Most likely, you would pass a reference to the progress bar or a related class into your ProgressMonitor constructor, and call it when you are notified of bytes transferred.

So, How would I get the variable 'answer' from the progressmonitor class back into the main program in order to update the progess bar?
0 votes
by (440 points)
Thank you. I have worked out the code, and it's clicking along!

Categories

...