diff --git a/src/main/java/duke/command/ExitCommand.java b/src/main/java/duke/command/ExitCommand.java index bf4b90c5de..eb6d19fe0a 100644 --- a/src/main/java/duke/command/ExitCommand.java +++ b/src/main/java/duke/command/ExitCommand.java @@ -8,6 +8,8 @@ * Encapsulates a command to terminate Duke. */ public class ExitCommand extends Command { + public static final String EXIT_RESPONSE = "bye..."; + /** * Executes the ExitCommand to terminate Duke. * @@ -17,7 +19,7 @@ public class ExitCommand extends Command { */ @Override public String execute(TaskList tasks, Ui ui, Storage storage) { - return "bye..."; + return EXIT_RESPONSE; } /** diff --git a/src/main/java/duke/ui/MainWindow.java b/src/main/java/duke/ui/MainWindow.java index 81e0e51de2..55978eb70b 100644 --- a/src/main/java/duke/ui/MainWindow.java +++ b/src/main/java/duke/ui/MainWindow.java @@ -3,6 +3,8 @@ import java.io.IOException; import duke.Duke; +import duke.command.ExitCommand; +import javafx.application.Platform; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.control.Button; @@ -66,5 +68,8 @@ private void handleUserInput() { dialogContainer.getChildren().addAll(DialogBox.getUserDialog(input, userImage), DialogBox.getDukeDialog(response, dukeImage)); userInput.clear(); + if (response == ExitCommand.EXIT_RESPONSE) { + Platform.exit(); + } } }