【发布时间】:2018-02-15 07:06:41
【问题描述】:
我对 Java 比较陌生,尤其是 Javafx 和 GUI。我一直在研究这段代码,但我在理解 THE VERY LAST LINE 的作用时遇到了一些麻烦。我知道倒数第二行是将所有组件添加到容器“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);
}
}
【问题讨论】:
标签: java user-interface javafx