Skip to content

Commit

Permalink
Implement Better GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterHW963 committed Sep 18, 2024
1 parent 98bf759 commit 8ce2e2c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/main/java/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ private DialogBox(String text, Image img) {
dialog.setText(text);
displayPicture.setClip(c);
displayPicture.setImage(img);

// Determine if the message is an error message and apply the appropriate style
if (isErrorMessage(text)) {
dialog.getStyleClass().add("error-label");
} else {
dialog.getStyleClass().add("label");
}
}

/**
* Determines if the given message should be treated as an error message.
* @param message The message to check.
* @return true if it's an error message, false otherwise.
*/
private boolean isErrorMessage(String message) {
// Define the logic to determine if a message is an error. This is just an example.
return message.toLowerCase().contains("sir,") || message.toLowerCase().contains("not in our database");
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ private void handleUserInput() {
String input = userInput.getText();
String response = nether.getResponse(input);
dialogContainer.getChildren().addAll(
DialogBox.getUserDialog(input, userImage),
DialogBox.getDukeDialog(response, netherImage)
DialogBox.getUserDialog(input, userImage),
DialogBox.getDukeDialog(response, netherImage)
);
userInput.clear();
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/css/dialog-box.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
-fx-border-radius: 1em 1em 1em 0;
}

.error-label {
-fx-background-color: #a52732; /* Light red background */
-fx-border-color: #721c24; /* Light red border */
-fx-text-fill: white; /* Dark red text for high contrast */
-fx-background-radius: 1em 1em 0 1em;
-fx-border-radius: 1em 1em 0 1em;
-fx-padding: 6px;
-fx-border-insets: 0px 7px 0px 7px;
-fx-background-insets: 0px 7px 0px 7px;
}

#displayPicture {
/* Shadow effect on image. */
-fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.2), 10, 0.5, 5, 5);
Expand Down

0 comments on commit 8ce2e2c

Please sign in to comment.