我已经实现了自己的javafx.concurrent.Task
,并且我想在其类声明之外调用其updateProgress
方法,但错误提示:updateProgress(double,double)已保护Task中的访问
例:
downloadTask.updateProgress(index,size);
这可能吗?
最佳答案
Javadoc:
https://docs.oracle.com/javafx/2/api/javafx/concurrent/Task.html
来自Javadoc的代码段:
public class IteratingTask extends Task<Integer> {
private final int totalIterations;
public IteratingTask(int totalIterations) {
this.totalIterations = totalIterations;
}
@Override protected Integer call() throws Exception {
int iterations = 0;
for (iterations = 0; iterations < totalIterations; iterations++) {
if (isCancelled()) {
updateMessage("Cancelled");
break;
}
updateMessage("Iteration " + iterations);
updateProgress(iterations, totalIterations);
}
return iterations;
}
}