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)); } }