Created
May 22, 2021 12:28
-
-
Save Da9el00/977187cee7a00cf528db5f63c9f2a75e to your computer and use it in GitHub Desktop.
JavaFX Alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import javafx.event.ActionEvent; | |
import javafx.fxml.FXML; | |
import javafx.scene.control.Alert; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.ButtonType; | |
import java.util.Optional; | |
public class Controller { | |
@FXML | |
void showDialog(ActionEvent event) { | |
Alert alert = new Alert(Alert.AlertType.CONFIRMATION); | |
alert.setTitle("Alert!"); | |
alert.setContentText("This is an alert"); | |
Optional<ButtonType> result = alert.showAndWait(); | |
if(result.isEmpty()){ | |
System.out.println("Alert closed"); | |
} else if(result.get() == ButtonType.OK){ | |
System.out.println("OK!"); | |
} else if(result.get() == ButtonType.CANCEL){ | |
System.out.println("Never!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment