Skip to content

Commit

Permalink
Add welcome message and rerefactor or MainWindow.java
Browse files Browse the repository at this point in the history
  • Loading branch information
aureliony committed Feb 19, 2024
1 parent 5d5cdbf commit b4145e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/main/java/cvb/ConvoBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/cvb/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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);
Expand All @@ -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));
}
}

0 comments on commit b4145e6

Please sign in to comment.