Skip to content

Commit

Permalink
Modify "bye" command behaviour
Browse files Browse the repository at this point in the history
-Ui class calls stage.close() to close the GUI window
  • Loading branch information
lerxcl committed Sep 13, 2020
1 parent 8e4b176 commit a8fcc9c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void start(Stage stage) {
Image icon = new Image(this.getClass().getResourceAsStream("/images/icon.jpg"));
stage.getIcons().add(icon);
fxmlLoader.<MainWindow>getController().setDuke(duke);
duke.getUi().stage = stage;
stage.show();
} catch (IOException e) {
e.printStackTrace();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ private void handleUserInput() {
);
userInput.clear();
}

}
10 changes: 8 additions & 2 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import javafx.stage.Stage;

import java.util.concurrent.TimeUnit;

/**
* Ui class deals with all of the interactions with the user.
*/
public class Ui {
protected Parser parser;
protected String divider = "____________________________________________________________";
protected Stage stage;

/**
* Constructor creates an Ui object.
Expand All @@ -12,6 +17,7 @@ public class Ui {
*/
public Ui(Parser parser) {
this.parser = parser;
this.stage = null;
}

/**
Expand Down Expand Up @@ -45,8 +51,8 @@ protected String run(String input) {
* @return goodbye message
*/
protected String goodbye() {
String message = divider + "\n" + "Bye. Hope to see you again soon! :)" + "\n" + divider;
return message;
this.stage.close();
return "bye!";
}

}

0 comments on commit a8fcc9c

Please sign in to comment.