Tech Geek
Tech Geek

Reputation: 465

JavaFx Concurrency Event

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);

Upvotes: 1

Views: 69

Answers (1)

James_D
James_D

Reputation: 209225

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();
}

Upvotes: 3

Related Questions