S
S
SoloCheater2018-08-05 20:39:40
Java
SoloCheater, 2018-08-05 20:39:40

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

1 answer(s)
C
Cheypnow, 2018-09-27
@Cheypnow

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 question

Ask a Question

731 491 924 answers to any question