se-edu / guides

Style guides and tutorials for SE student projects
MIT License
5 stars 20 forks source link

[JavaFX-Part 3] Refactor class DialogBox and method handleUserInput #23

Open JiaXinEu opened 2 weeks ago

JiaXinEu commented 2 weeks ago

Current:

image image

Problem:

Label and ImageView is created in handleUserInput and passed to DialogBox, which may increase dependency and reduce readability of code.

Proposed:

Constructor of DialogBox can be something as below:

public DialogBox (String s, Image i) {
    text = new Label(s);
    displayPicture = new ImageView(i);
    // ...
}

handleUserInput can be something as below:

private void handleUserInput() {
    String userText = userInput.getText();
    String dukeText = getResponse(userInput.getText());
    dialogContainer.getChildren().addAll(
            new DialogBox(userText, user),
            new DialogBox(dukeText, duke)
    );
    userInput.clear();
}
damithc commented 1 week ago

@JiaXinEu You can send a PR for this.