Answer the question
In order to leave comments, you need to log in
How to make a confirmation dialog box (yes/no) before running the Java program itself?
Hello. I am making a program in Java. There was an idea to make a confirmation (yes/no) before running my java program.
A window should pop up with a message like - "Are you sure you want to run the program?"
How to do it?
Answer the question
In order to leave comments, you need to log in
If in JavaFX, use Confirmation Alert.
More or less like this:
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Запуск программы");
alert.setHeaderText("Вы действительно хотите запустить программу?");
alert.setContentText("Нажмите ОК для запуска и Cancel для отмены");
Optional<ButtonType> option = alert.showAndWait();
if (option.get() == null || option.get() == ButtonType.CANCEL) {
// закрываешь программу
} else if (option.get() == ButtonType.OK) {
// запускаешь
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question