Skip to content

Commit

Permalink
feat: closes GUI when user inputs bye
Browse files Browse the repository at this point in the history
Duke now closes when user inputs bye.
  • Loading branch information
zupey committed Sep 7, 2022
1 parent f4986f7 commit 77588f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
public class Duke {

private boolean isClosed;
private final TaskList taskList;
private final CommandHandlerFactory commandHandlerFactory;

Expand All @@ -34,6 +35,15 @@ public Duke() {
Storage db = new Storage("./data/duke.txt");
taskList = db.load();
commandHandlerFactory = new CommandHandlerFactory();
isClosed = false;
}

/**
* Checks if duke has terminated.
* @return whether duke has terminated.
*/
public boolean isClosed() {
return isClosed;
}

/**
Expand All @@ -42,6 +52,9 @@ public Duke() {
* @return Duke's response to the user.
*/
public String getResponse(String input) {
if (input.equals("bye")) {
this.isClosed = true;
}
try {
CommandHandler commandHandler = commandHandlerFactory.getHandler(input);
return commandHandler.handle(taskList);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/duke/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package duke;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
Expand Down Expand Up @@ -50,5 +51,9 @@ private void handleUserInput() {
DialogBox.getDukeDialog(response, dukeImage)
);
userInput.clear();

if (duke.isClosed()) {
Platform.exit();
}
}
}

0 comments on commit 77588f8

Please sign in to comment.