1
我对JavaFX应用程序更新工作,在那里,我有一个脚本,提取一个zip其次是一些其他操作如更新文件等文本区域不同时ZIP解压
我想有一个显示什么包含textArea在后台正在进行,如 “ZIP解压......”, “更新XYZ文件” 等
到现在我已经尝试以下方法:
MyTask<String> task;
task = new MyTask<String>() {
@Override
protected String call() throws Exception {
File path = new File(exportTo.getAbsolutePath());
updateMessage("Extracting modular app to target directory...");
patcher.unZip(appPath.getAbsolutePath(), path.getAbsolutePath());
if (path.exists()) {
AppInfo info = getAppInfo();
patcher.patchAndroid(info, resourceZip, new File(path.getAbsolutePath() + "/" + appPath.getName().substring(0, appPath.getName().lastIndexOf("."))), this);
showOkAlert("Build completed!");
} else {
showOkAlert("Modular app folder not found");
}
return "";
}
@Override
protected void updateProgress(double workDone, double max) {
patcher.reportLogs(message);
}
private String message;
@Override
public void updateMessage(final String message) {
Platform.runLater(() -> patcher.reportLogs(message));
this.message = message;
//updateProgress(0, 0);
}
};
task.run();
MyTask类
abstract class MyTask<T> extends Task<T> {
abstract public void updateMessage(String message);
}
我试过使用updateProgress方法,Platform.runLater()但没有任何工作。
在完成所有操作后,打印出的所有信息都印在textArea中。
请帮忙。
你需要在新线程上运行你的'Task',参见例如https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/concurrency.htm – Itai
@sillyfly非常感谢。解决了我的问题。 – chandil03
然后考虑删除你的问题... – GhostCat