From 9da2281eac70d27f210082f8638566c947b34f1a Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 21:04:32 +0100 Subject: [PATCH] add setName and Color to CardController --- .../onses/controllers/CardController.java | 20 ++++++++++++++++ .../de/hsfulda/onses/views/card.fxml | 24 ++++++++++++------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/hsfulda/onses/controllers/CardController.java b/src/main/java/de/hsfulda/onses/controllers/CardController.java index c84835d..1ef955e 100644 --- a/src/main/java/de/hsfulda/onses/controllers/CardController.java +++ b/src/main/java/de/hsfulda/onses/controllers/CardController.java @@ -1,17 +1,37 @@ package de.hsfulda.onses.controllers; import de.hsfulda.onses.Main; +import de.hsfulda.onses.models.Card; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; +import javafx.scene.control.Label; +import javafx.scene.layout.Pane; import java.io.IOException; import java.util.Objects; public class CardController implements Controller { + + private Card card; + + public CardController(Card card) { + this.card = card; + } @Override public Parent render() throws IOException { final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/card.fxml"))); + Pane mainPane = (Pane) parent.lookup("#cardPane"); + + mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: red")); + + final Label cardName = (Label) parent.lookup("#labelName"); + cardName.setText(this.card.getValue().name()); + return parent; } + + private String addStyle(String oldStyle, String newStyle) { + return oldStyle + "; " + newStyle; + } } diff --git a/src/main/resources/de/hsfulda/onses/views/card.fxml b/src/main/resources/de/hsfulda/onses/views/card.fxml index fd33361..4d7f84d 100644 --- a/src/main/resources/de/hsfulda/onses/views/card.fxml +++ b/src/main/resources/de/hsfulda/onses/views/card.fxml @@ -1,13 +1,19 @@ - - - - - - - + + + + + + + + + + +