我正在使用下载器创建 Java 应用程序。我的问题是,进度条不起作用。我希望我的进度条显示下载进度但失败了。这是我的代码的一部分。进度条一直停留在 0%...
下载.class
public void startDownload()
{
ExecutorService executor = Executors.newSingleThreadExecutor();
FutureTask<Void> verDownloader = new FutureTask<Void>(vd);
FutureTask<Void> launcher = new FutureTask<Void>(dd);
executor.execute(verDownloader);
executor.execute(launcher);
executor.shutdown();
}
版本下载器类
public class VersionDownloader implements Callable<Void>, PropertyChangeListener
{
@Override
public Void call() throws Exception
{
done = false;
final SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>()
{
@Override
protected Void doInBackground() throws Exception
{
try
{
URL fileURL = new URL(url);
org.apache.commons.io.FileUtils.copyURLToFile(fileURL, path);
}
catch(Exception e)
{
}
return null;
}
@Override
public void done()
{
done = true;
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
};
worker.execute();
worker.addPropertyChangeListener(this);
worker.get();
}
}
}
catch(Exception e)
{
}
return null;
}
@Override
public void propertyChange(PropertyChangeEvent evt)
{
if(!done)
{
int progress_a = progress;
//launcher.frame.progress is a JProgressBar
launcher.frame.progress.setValue(progress_a);
}
}
}
那有什么代码错了吗?