本文整理汇总了Java中javafx.scene.Group.getChildren方法的典型用法代码示例。如果您正苦于以下问题:Java Group.getChildren方法的具体用法?Java Group.getChildren怎么用?Java Group.getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.Group
的用法示例。
在下文中一共展示了Group.getChildren方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setGroupColor
import javafx.scene.Group; //导入方法依赖的package包/类
private void setGroupColor(Group group, Color color) {
if (group != null) {
for(Node child: group.getChildren()) {
if (child instanceof Shape) {
((Shape)child).setFill(color);
} else if (child instanceof Group) {
setGroupColor((Group)child,color);
}
}
}
}
示例2: createNumberGroup
import javafx.scene.Group; //导入方法依赖的package包/类
/**
* Create a new number group to render the provided number [0..9] in JavaFX.
* @param number The number to create.
* @return A new group that can be used to render the provided number.
* @throws IllegalArgumentException Whether any invalid number was given.
*/
private static Group createNumberGroup(int number) throws IllegalArgumentException {
Args.isBetween(number, 0, 9, "The number must be within the [0..9] range!");
// @formatter:off
// construct a new group with the necessary graphics.
Group group = new Group();
ObservableList<Node> children = group.getChildren();
switch (number) {
case 0:
children.add(whiteRect(0, 0, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(0, 0, NUMBER_THICKNESS, NUMBER_HEIGHT));
children.add(whiteRect(NUMBER_WIDTH - NUMBER_THICKNESS, 0, NUMBER_THICKNESS, NUMBER_HEIGHT));
children.add(whiteRect(0, NUMBER_HEIGHT - NUMBER_THICKNESS, NUMBER_WIDTH, NUMBER_THICKNESS));
break;
case 1:
children.add(whiteRect(NUMBER_WIDTH / 2 - NUMBER_THICKNESS, 0, NUMBER_THICKNESS, NUMBER_HEIGHT));
break;
case 2:
children.add(whiteRect(0, 0, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(NUMBER_WIDTH - NUMBER_THICKNESS, 0, NUMBER_THICKNESS, NUMBER_HEIGHT / 2));
children.add(whiteRect(0, NUMBER_HEIGHT / 2 - NUMBER_THICKNESS / 2, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(0, NUMBER_HEIGHT / 2, NUMBER_THICKNESS, NUMBER_HEIGHT / 2));
children.add(whiteRect(0, NUMBER_HEIGHT - NUMBER_THICKNESS, NUMBER_WIDTH, NUMBER_THICKNESS));
break;
case 3:
children.add(whiteRect(0, 0, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(0, NUMBER_HEIGHT / 2 - NUMBER_THICKNESS / 2, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(0, NUMBER_HEIGHT - NUMBER_THICKNESS, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(NUMBER_WIDTH - NUMBER_THICKNESS, 0, NUMBER_THICKNESS, NUMBER_HEIGHT));
break;
case 4:
children.add(whiteRect(0, 0, NUMBER_THICKNESS, NUMBER_HEIGHT / 2));
children.add(whiteRect(0, NUMBER_HEIGHT / 2 - NUMBER_THICKNESS / 2, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(NUMBER_WIDTH - NUMBER_THICKNESS, 0, NUMBER_THICKNESS, NUMBER_HEIGHT));
break;
case 5:
children.add(whiteRect(0, 0, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(0, 0, NUMBER_THICKNESS, NUMBER_HEIGHT / 2));
children.add(whiteRect(0, NUMBER_HEIGHT / 2 - NUMBER_THICKNESS / 2, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(NUMBER_WIDTH - NUMBER_THICKNESS, NUMBER_HEIGHT / 2, NUMBER_THICKNESS, NUMBER_HEIGHT / 2));
children.add(whiteRect(0, NUMBER_HEIGHT - NUMBER_THICKNESS, NUMBER_WIDTH, NUMBER_THICKNESS));
break;
case 6:
children.add(whiteRect(0, 0, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(0, 0, NUMBER_THICKNESS, NUMBER_HEIGHT));
children.add(whiteRect(0, NUMBER_HEIGHT / 2 - NUMBER_THICKNESS / 2, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(NUMBER_WIDTH - NUMBER_THICKNESS, NUMBER_HEIGHT / 2, NUMBER_THICKNESS, NUMBER_HEIGHT / 2));
children.add(whiteRect(0, NUMBER_HEIGHT - NUMBER_THICKNESS, NUMBER_WIDTH, NUMBER_THICKNESS));
break;
case 7:
children.add(whiteRect(0, 0, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(NUMBER_WIDTH - NUMBER_THICKNESS, 0, NUMBER_THICKNESS, NUMBER_HEIGHT));
break;
case 8:
children.add(whiteRect(0, 0, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(0, 0, NUMBER_THICKNESS, NUMBER_HEIGHT));
children.add(whiteRect(0, NUMBER_HEIGHT / 2 - NUMBER_THICKNESS / 2, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(NUMBER_WIDTH - NUMBER_THICKNESS, 0, NUMBER_THICKNESS, NUMBER_HEIGHT));
children.add(whiteRect(0, NUMBER_HEIGHT - NUMBER_THICKNESS, NUMBER_WIDTH, NUMBER_THICKNESS));
break;
case 9:
children.add(whiteRect(0, 0, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(0, 0, NUMBER_THICKNESS, NUMBER_HEIGHT / 2));
children.add(whiteRect(0, NUMBER_HEIGHT / 2 - NUMBER_THICKNESS / 2, NUMBER_WIDTH, NUMBER_THICKNESS));
children.add(whiteRect(NUMBER_WIDTH - NUMBER_THICKNESS, 0, NUMBER_THICKNESS, NUMBER_HEIGHT));
children.add(whiteRect(0, NUMBER_HEIGHT - NUMBER_THICKNESS, NUMBER_WIDTH, NUMBER_THICKNESS));
break;
default:
break;
}
// @formatter:on
return group;
}
示例3: WelcomeScene
import javafx.scene.Group; //导入方法依赖的package包/类
public WelcomeScene(PongApplication application) throws NullPointerException {
super(new Group(), RESOLUTION_WIDTH, RESOLUTION_HEIGHT);
requireNonNull(application, "The application cannot be null!");
topicText = new Text("JavaFX Pong");
topicText.setTextOrigin(VPos.CENTER);
topicText.setFont(BIG_FONT);
topicText.setLayoutX((RESOLUTION_WIDTH - topicText.prefWidth(-1)) / 2);
topicText.setLayoutY(RESOLUTION_HEIGHT / 6);
topicText.setFill(Color.WHITE);
leftControlsTopicText = new Text("Controls for the left player:");
leftControlsTopicText.setTextOrigin(VPos.CENTER);
leftControlsTopicText.setFont(SMALL_FONT);
leftControlsTopicText.setLayoutX((RESOLUTION_WIDTH - leftControlsTopicText.prefWidth(-1)) / 2);
leftControlsTopicText.setLayoutY(topicText.getLayoutY() + 100);
leftControlsTopicText.setFill(Color.WHITE);
leftControlsText = new Text("W and S");
leftControlsText.setTextOrigin(VPos.CENTER);
leftControlsText.setFont(SMALL_FONT);
leftControlsText.setLayoutX((RESOLUTION_WIDTH - leftControlsText.prefWidth(-1)) / 2);
leftControlsText.setLayoutY(leftControlsTopicText.getLayoutY() + 40);
leftControlsText.setFill(Color.WHITE);
rightControlsTopicText = new Text("Controls for the right player:");
rightControlsTopicText.setTextOrigin(VPos.CENTER);
rightControlsTopicText.setFont(SMALL_FONT);
rightControlsTopicText.setLayoutX((RESOLUTION_WIDTH - rightControlsTopicText.prefWidth(-1)) / 2);
rightControlsTopicText.setLayoutY(leftControlsText.getLayoutY() + 60);
rightControlsTopicText.setFill(Color.WHITE);
rightControlsText = new Text("UP-ARROW and DOWN-ARROW");
rightControlsText.setTextOrigin(VPos.CENTER);
rightControlsText.setFont(SMALL_FONT);
rightControlsText.setLayoutX((RESOLUTION_WIDTH - rightControlsText.prefWidth(-1)) / 2);
rightControlsText.setLayoutY(rightControlsTopicText.getLayoutY() + 40);
rightControlsText.setFill(Color.WHITE);
proceedInstructionsText = new Text("Press [ENTER] to start the match");
proceedInstructionsText.setTextOrigin(VPos.CENTER);
proceedInstructionsText.setFont(SMALL_FONT);
proceedInstructionsText.setLayoutX((RESOLUTION_WIDTH - proceedInstructionsText.prefWidth(-1)) / 2);
proceedInstructionsText.setLayoutY(rightControlsTopicText.getLayoutY() + 160);
proceedInstructionsText.setFill(Color.WHITE);
Parent root = getRoot();
if (!(root instanceof Group)) {
throw new AssertionError("The scene root is not a Group instance!");
}
Group rootGroup = (Group) root;
ObservableList<Node> children = rootGroup.getChildren();
children.add(topicText);
children.add(leftControlsTopicText);
children.add(leftControlsText);
children.add(rightControlsTopicText);
children.add(rightControlsText);
children.add(proceedInstructionsText);
setOnKeyReleased(x -> {
if (x.getCode() == KeyCode.ENTER) {
// move into the court scene so we can start the game.
Stage primaryStage = application.getPrimaryStage();
primaryStage.setScene(new CourtScene(application));
}
});
setFill(Color.BLACK);
}
示例4: EndGameScene
import javafx.scene.Group; //导入方法依赖的package包/类
public EndGameScene(PongApplication application) throws NullPointerException {
super(new Group(), RESOLUTION_WIDTH, RESOLUTION_HEIGHT);
requireNonNull(application, "The application cannot be null!");
// get player scores from the session context.
PongContext ctx = requireNonNull(application.getContext(), "The context cannot be null!");
int p1Score = ctx.getPlayer1Score();
int p2Score = ctx.getPlayer2Score();
topicText = new Text("JavaFX Pong - Results");
topicText.setTextOrigin(VPos.CENTER);
topicText.setFont(BIG_FONT);
topicText.setLayoutX((RESOLUTION_WIDTH - topicText.prefWidth(-1)) / 2);
topicText.setLayoutY(RESOLUTION_HEIGHT / 6);
topicText.setFill(Color.WHITE);
gameHasEndedText = new Text("Game has ended");
gameHasEndedText.setTextOrigin(VPos.CENTER);
gameHasEndedText.setFont(SMALL_FONT);
gameHasEndedText.setLayoutX((RESOLUTION_WIDTH - gameHasEndedText.prefWidth(-1)) / 2);
gameHasEndedText.setLayoutY(topicText.getLayoutY() + 100);
gameHasEndedText.setFill(Color.WHITE);
winnerText = new Text((p1Score > p2Score ? "Right" : "Left") + " player won the game!");
winnerText.setTextOrigin(VPos.CENTER);
winnerText.setFont(SMALL_FONT);
winnerText.setLayoutX((RESOLUTION_WIDTH - winnerText.prefWidth(-1)) / 2);
winnerText.setLayoutY(gameHasEndedText.getLayoutY() + 40);
winnerText.setFill(Color.WHITE);
resultsTopicText = new Text("End results:");
resultsTopicText.setTextOrigin(VPos.CENTER);
resultsTopicText.setFont(SMALL_FONT);
resultsTopicText.setLayoutX((RESOLUTION_WIDTH - resultsTopicText.prefWidth(-1)) / 2);
resultsTopicText.setLayoutY(winnerText.getLayoutY() + 40);
resultsTopicText.setFill(Color.WHITE);
resultsText = new Text("" + ctx.getPlayer2Score() + " - " + ctx.getPlayer1Score());
resultsText.setTextOrigin(VPos.CENTER);
resultsText.setFont(SMALL_FONT);
resultsText.setLayoutX((RESOLUTION_WIDTH - resultsText.prefWidth(-1)) / 2);
resultsText.setLayoutY(resultsTopicText.getLayoutY() + 40);
resultsText.setFill(Color.WHITE);
proceedInstructionsText = new Text("Press [ENTER] to proceed");
proceedInstructionsText.setTextOrigin(VPos.CENTER);
proceedInstructionsText.setFont(SMALL_FONT);
proceedInstructionsText.setLayoutX((RESOLUTION_WIDTH - proceedInstructionsText.prefWidth(-1)) / 2);
proceedInstructionsText.setLayoutY(resultsText.getLayoutY() + 160);
proceedInstructionsText.setFill(Color.WHITE);
Parent root = getRoot();
if (!(root instanceof Group)) {
throw new AssertionError("The scene root is not a Group instance!");
}
Group rootGroup = (Group) root;
ObservableList<Node> children = rootGroup.getChildren();
children.add(topicText);
children.add(gameHasEndedText);
children.add(winnerText);
children.add(resultsTopicText);
children.add(resultsText);
children.add(proceedInstructionsText);
setOnKeyReleased(x -> {
if (x.getCode() == KeyCode.ENTER) {
// reset the game state and move into the welcoming scene.
ctx.reset();
Stage primaryStage = application.getPrimaryStage();
primaryStage.setScene(new WelcomeScene(application));
}
});
setFill(Color.BLACK);
}