JavaFX并发事件

huangapple go评论69阅读模式
英文:

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(&quot;Update Now&quot;, ButtonData.OK_DONE);
buttonTypes[1] = new ButtonType(&quot;Update Later&quot;, ButtonData.CANCEL_CLOSE);
EventHandler[] eventHandlers = new EventHandler[2];
eventHandlers[0] = new EventHandler&lt;ActionEvent&gt;() {
                @Override
                public void handle(ActionEvent event) {
                   ;
                }
            };
                    
eventHandlers[1] = new EventHandler&lt;ActionEvent&gt;() {
@Override
public void handle(ActionEvent event) {
 }
 };     
Dialog.AlertDialog(Alert.AlertType.CONFIRMATION, Main.productName, &quot;Update Confirmation&quot;, &quot;New Update is available. DO you want to update ?&quot;, 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 -&gt; {
        // whatever you need to do in 30 minutes....
    });
    delay.play();
}

huangapple
  • 本文由 发表于 2020年9月1日 00:47:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/63674903.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定