我的JavaFX程序上有一个名为woodcuttingButton的按钮,当它被点击时,它会提醒玩家选择他们想要剪切的树。
不幸的是,当点击按钮时,没有任何反应。
woodcuttingButton.setOnAction(e -> {
alert.setTitle("Woodcutting");
alert.setHeaderText("What tree would you like to cut?");
alert.setContentText("Choose your option.");
ButtonType buttonTypeOak = new ButtonType("Oak");
ButtonType buttonTypeWillow = new ButtonType("Willow");
ButtonType buttonTypeMaple = new ButtonType("Maple");
ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);
alert.getButtonTypes().setAll(buttonTypeOak, buttonTypeWillow, buttonTypeMaple, buttonTypeCancel);
});
我是否错误地实施了警报?
答案 0 :(得分:3)
它已正确实施(至少已显示)但您需要显示对话框
{{1}}