Java中的复合组件
我正在为一个uni项目(炉石)制作一个战斗卡游戏 船上的“仆从”牌有生命值和攻击值,而且它们不断变化,我正在尝试制作一个复合组件,它将是一个中心Java中的复合组件,java,user-interface,javafx-8,Java,User Interface,Javafx 8,我正在为一个uni项目(炉石)制作一个战斗卡游戏 船上的“仆从”牌有生命值和攻击值,而且它们不断变化,我正在尝试制作一个复合组件,它将是一个中心ImageIcon,在左下方和右下方有两个“正方形”,表示卡的当前生命值和攻击值,在左上方有一个,表示其成本,所有这些都是StringProperty 我真的不知道如何处理这个问题,也许一个复合组件甚至不是必需的 这是炉石卡外观的一个示例: 使用堆叠窗格。把图片放在底部,然后在顶部放一个锚烷。在三个角中的每个角中放置一个文本,并将每个角的textProp
ImageIcon
,在左下方和右下方有两个“正方形”,表示卡的当前生命值和攻击值,在左上方有一个,表示其成本,所有这些都是StringProperty
我真的不知道如何处理这个问题,也许一个复合组件甚至不是必需的
这是炉石卡外观的一个示例:
使用堆叠窗格。把图片放在底部,然后在顶部放一个锚烷。在三个角中的每个角中放置一个文本,并将每个角的textProperty()绑定到其中一个StringProperties。大概是这样的:
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);
}
}
}