英文:
JavaFx Concurrency Event
问题
ButtonType[] buttonTypes = new ButtonType[2];
buttonTypes[0] = new ButtonType("立即更新", ButtonData.OK_DONE);
buttonTypes[1] = new ButtonType("稍后更新", ButtonData.CANCEL_CLOSE);
EventHandler[] eventHandlers = new EventHandler[2];
eventHandlers[0] = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// 在这里处理立即更新的逻辑
}
};
eventHandlers[1] = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// 在这里处理稍后更新的逻辑
}
};
Dialog.AlertDialog(
Alert.AlertType.CONFIRMATION,
Main.productName,
"更新确认",
"有新的更新可用。您想要更新吗?",
buttonTypes,
Modality.APPLICATION_MODAL,
StageStyle.DECORATED,
stage,
eventHandlers
);
注意:上述代码为您提供了原始代码的翻译,但没有添加时间延迟的功能。如果您希望在点击"稍后更新"后30分钟再次显示对话框,您需要在适当的位置添加计时器和相应的逻辑来实现此功能。
英文:
I have a problem in JavaFx code.
I have one dialog box. Which has 2 buttons UPDATE NOW and UPDATE LATER.
My problem is : when I click on "UPDATE LATER" the dialog box should close and after 30 mins again it should pop up the same dialog box.
My main thread will be running only. I just need to remind it again after 30 mins whenever I click on UPDATE LATER.
Please help how can I do that in javaFx.
ButtonType[] buttonTypes = new ButtonType[2];
buttonTypes[0] = new ButtonType("Update Now", ButtonData.OK_DONE);
buttonTypes[1] = new ButtonType("Update Later", ButtonData.CANCEL_CLOSE);
EventHandler[] eventHandlers = new EventHandler[2];
eventHandlers[0] = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
;
}
};
eventHandlers[1] = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
}
};
Dialog.AlertDialog(Alert.AlertType.CONFIRMATION, Main.productName, "Update Confirmation", "New Update is available. DO you want to update ?", buttonTypes, Modality.APPLICATION_MODAL, StageStyle.DECORATED, stage, eventHandlers);
答案1
得分: 3
为了在一段时间后执行某些操作,使用PauseTransition
。
在这种情况下,您可以这样做:
public void handle(ActionEvent event) {
PauseTransition delay = new PauseTransition(Duration.minutes(30));
delay.setOnFinished(evt -> {
// 30分钟后需要执行的操作....
});
delay.play();
}
英文:
To do something after some period of time, use a PauseTransition
.
In this case, you can do
public void handle(ActionEvent event) {
PauseTransition delay = new PauseTransition(Duration.minutes(30));
delay.setOnFinished(evt -> {
// whatever you need to do in 30 minutes....
});
delay.play();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论