import java.util.Optional; 

import javafx.application.Application; 
import javafx.scene.control.Alert; 
import javafx.scene.control.Alert.AlertType; 
import javafx.scene.control.ButtonBar.ButtonData; 
import javafx.scene.control.ButtonType; 
import javafx.stage.Stage; 

public class Main extends Application { 

    public static void main(final String[] args) { 
        launch(); 
    } 

    private static boolean isYes(final Optional<ButtonType> result) { 
        return (result.isPresent() && result.get().getButtonData() == ButtonData.YES); 
    } 

    @Override 
    public void start(Stage primaryStage) throws Exception { 
        final Alert alert = new Alert(AlertType.CONFIRMATION, 
            "This is a test", ButtonType.NO, ButtonType.YES); 
        System.out.println(isYes(alert.showAndWait()) ? "Yes" : "No or Closed"); 
        System.out.println(isYes(alert.showAndWait()) ? "Yes" : "No or Closed"); 
    } 

} 