From b4145e6309cc06ef9108b5ebfdba389cebc32ba9 Mon Sep 17 00:00:00 2001 From: aureliony <39163684+aureliony@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:56:28 +0800 Subject: [PATCH] Add welcome message and rerefactor or MainWindow.java --- src/main/java/cvb/ConvoBot.java | 10 ++++++++++ src/main/java/cvb/gui/MainWindow.java | 20 +++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/cvb/ConvoBot.java b/src/main/java/cvb/ConvoBot.java index dfcbe876e7..4c91650ff3 100755 --- a/src/main/java/cvb/ConvoBot.java +++ b/src/main/java/cvb/ConvoBot.java @@ -27,6 +27,16 @@ public ConvoBot(String filePath) { tasks = new TaskList(new Storage(filePath)); } + /** + * Returns the welcome message. + * + * @return The welcome message. + */ + public String getWelcome() { + rc.showWelcomeMsg(); + return rc.getResponse(); + } + /** * Retrieves a response from ConvoBot based on the provided input. * diff --git a/src/main/java/cvb/gui/MainWindow.java b/src/main/java/cvb/gui/MainWindow.java index 215d922694..cbd58bbece 100755 --- a/src/main/java/cvb/gui/MainWindow.java +++ b/src/main/java/cvb/gui/MainWindow.java @@ -26,12 +26,11 @@ public class MainWindow extends AnchorPane { private VBox dialogContainer; @FXML private TextField userInput; - @FXML - private Button sendButton; @FXML - public void initialize() { + private void initialize() { dialogContainer.heightProperty().addListener(observable -> scrollPane.setVvalue(1.0)); + addResponse(convo.getWelcome()); } /** @@ -44,6 +43,8 @@ private void handleUserInput() { userInput.requestFocus(); // re-focus TextField String input = userInput.getText(); userInput.clear(); + addInput(input); + String response = ""; try { response = convo.getResponse(input); @@ -52,9 +53,14 @@ private void handleUserInput() { return; } assert !response.isEmpty(); - dialogContainer.getChildren().addAll( - DialogBox.getUserDialog(input, userImage), - DialogBox.getConvoBotDialog(response, convoImage) - ); + addResponse(response); + } + + private void addInput(String input) { + dialogContainer.getChildren().addAll(DialogBox.getUserDialog(input, userImage)); + } + + private void addResponse(String response) { + dialogContainer.getChildren().addAll(DialogBox.getConvoBotDialog(response, convoImage)); } }