我得到以下数据模型:
public class Player {
// enum to integer (count)
@Getter
private MapProperty<ResourceType, Integer> resourceCards = new SimpleMapProperty<>();
public void addResource(final ResourceType resourceType, final int amount) {
this.resourceCards.get().put(resourceType, this.resourceCards.get().get(resourceType) + amount);
}
}
public class Game {
@Getter
@Setter
private ObjectProperty<Player> currentPlayer = new SimpleObjectProperty<>();
}
将地图绑定到文本属性非常简单:
final Label label = new Label();
label.textProperty().bind(EasyBind.select(game.getCurrentPlayer()).selectObject(player -> player.getResourceCards().asString()));
我想在标签中显示资源卡的总量。
例子:
地图:{水=0,金=2,木材=5}
标签: 7
地图:{水=0,金=0,木材=0}
标签: 0
如何使用 JavaFX Bindings 或/和EasyBind实现这一目标?