gpt4 book ai didi

java - 当您单独调用 getChildren 时会发生什么?

转载 作者:行者123 更新时间:2023-12-01 19:58:04 27 4
gpt4 key购买 nike

我对 Java 比较陌生,尤其是 Javafx 和 GUI。我一直在研究这段代码,但我在理解最后一行正在做什么时遇到了一些困难。我知道倒数第二行是将所有组件添加到容器“p”中,但是当您在前面没有容器的情况下调用 getChildren() 时会发生什么。无论如何,任何帮助都是值得赞赏的。

import javafx.scene.control.Button;
import javafx.scene.layout.Pane;

public class DVDButtonPane extends Pane {

public DVDButtonPane(){
Pane p = new Pane();

Button add = new Button("Add");
add.setPrefSize(95, 30);
add.relocate(0, 0);
add.setStyle("-fx-font: 12 arial; -fx-base: rgb(0,100,0); -fx-text-fill: rgb(255,255,255);");

Button delete = new Button("Delete");
delete.setPrefSize(90, 30);
delete.relocate(100, 0);
delete.setStyle("-fx-font: 12 arial; -fx-base: rgb(100,0,0); -fx-text-fill: rgb(255,255,255);");

Button stats = new Button("Stats");
stats.setPrefSize(90, 30);
stats.relocate(210, 0);

p.getChildren().addAll(add, delete, stats);
getChildren().add(p);
}
}

最佳答案

getChildren 与调用 this.getChildren 相同。该行将 p 添加到 DVDButtonPane 的子集合中。

关于java - 当您单独调用 getChildren 时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48801627/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com