Browse Source

add setName and Color to CardController

main
fdai7736 11 months ago
parent
commit
9da2281eac
  1. 20
      src/main/java/de/hsfulda/onses/controllers/CardController.java
  2. 24
      src/main/resources/de/hsfulda/onses/views/card.fxml

20
src/main/java/de/hsfulda/onses/controllers/CardController.java

@ -1,17 +1,37 @@
package de.hsfulda.onses.controllers; package de.hsfulda.onses.controllers;
import de.hsfulda.onses.Main; import de.hsfulda.onses.Main;
import de.hsfulda.onses.models.Card;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
public class CardController implements Controller { public class CardController implements Controller {
private Card card;
public CardController(Card card) {
this.card = card;
}
@Override @Override
public Parent render() throws IOException { public Parent render() throws IOException {
final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/card.fxml"))); 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; return parent;
} }
private String addStyle(String oldStyle, String newStyle) {
return oldStyle + "; " + newStyle;
}
} }

24
src/main/resources/de/hsfulda/onses/views/card.fxml

@ -1,13 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
prefHeight="400.0" prefWidth="600.0">
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="cardPane" prefHeight="200.0" prefWidth="130.0" style="-fx-border-color: black; -fx-border-width: 3px;" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="labelName" alignment="CENTER" layoutX="45.0" layoutY="91.0" text="1" textAlignment="CENTER" wrapText="true" AnchorPane.bottomAnchor="80.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="80.0">
<font>
<Font size="15.0" />
</font>
</Label>
</children>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</AnchorPane> </AnchorPane>
Loading…
Cancel
Save