我已经实现了自己的javafx.concurrent.Task
,我想在其类声明之外调用它的updateProgress
方法,但错误说: updateProgress(double,double)在Task中具有受保护的访问权限
示例:
downloadTask.updateProgress(index,size);
这可能吗?
答案 0 :(得分:0)
的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;
}
}