JavaFX create alert and get result

后端 未结 2 562
耶瑟儿~
耶瑟儿~ 2021-01-22 17:29

For my CS class they require us to use JavaFX alerts. I can make an alert appear, but how do I get what button was clicked? What would be the best way to go about getting this d

2条回答
  •  抹茶落季
    2021-01-22 18:02

    İf you want to do it with Non-Blocking type of code:

    final Alert alert2 = new Alert(Alert.AlertType.CONFIRMATION);
    alert2.show();
    alert2.setOnCloseRequest(new EventHandler() {
        @Override
        public void handle(DialogEvent event) {
            ButtonType result=alert2.getResult();
            String resultText=result.getText();
            //result logic
        }
    });
    

提交回复
热议问题