首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java中的复合组件

Java中的复合组件
EN

Stack Overflow用户
提问于 2016-04-19 00:44:12
回答 1查看 88关注 0票数 3

我正在为一个uni项目制作一款战斗纸牌游戏(炉石)

棋盘上的“小精灵”牌有生命值和攻击值,这些都是不断变化的,我正在尝试制作一个复合组件,它将是一个中心ImageIcon,在左下角和右下角有两个“正方形”,代表卡片当前的生命值和攻击值,在左上角有一个,代表它的费用,所有这些都是StringProperty

我真的不知道如何处理这件事,也许一个复合组件甚至不是必要的

这是一个炉石卡片的示例:

EN

回答 1

Stack Overflow用户

发布于 2016-05-17 09:33:22

使用StackPane。将图像放在底部,然后将AnchorPane放在顶部。在三个角中的每个角中放置一个文本,并将每个角的textProperty()绑定到其中一个StringProperties。如下所示:

代码语言:javascript
复制
public class BattleCard extends Application {

private static Label label;

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Hello World!");
    label = new Label();
    label.setText("Waiting...");
    StackPane root = new StackPane();
    root.getChildren().add(new CardPane());
    primaryStage.setScene(new Scene(root, 350, 420));
    primaryStage.show();
}

public class CardPane extends StackPane {
    public CardPane() {
        ImageView cardImage = new ImageView(new Image("http://i.stack.imgur.com/1ljQH.png"));
        AnchorPane anchorPane = new AnchorPane();
        getChildren().addAll(cardImage, anchorPane);
        Text costText = new Text("Cost");
        Text healthText = new Text("Health");
        Text attackText = new Text("Attack");
        AnchorPane.setTopAnchor(costText, 0d);
        AnchorPane.setLeftAnchor(costText, 0d);
        AnchorPane.setBottomAnchor(healthText, 0d);
        AnchorPane.setLeftAnchor(healthText, 0d);
        AnchorPane.setBottomAnchor(attackText, 0d);
        AnchorPane.setRightAnchor(attackText, 0d);
        anchorPane.getChildren().addAll(costText, healthText, attackText);
    }
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36699735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档