JavaFX,外部类扩展窗格,将其添加到主类不起作用 [英] JavaFX, external class extends pane, adding that to main class doesn't work
本文介绍了JavaFX,外部类扩展窗格,将其添加到主类不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
JavaFX主类:
public class Test1 extends Application {
@Override
public void start(Stage stage) throws Exception {
Pane sp = new Pane();
SubClass sc = new SubClass();
sc.c.setFill(Color.AQUA);
sp.getChildren().add(sc);
Scene scene = new Scene(sp, 250, 250);
stage.setTitle("Testing");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
这是我的另一堂课:
public class SubClass extends Pane
{
Circle c = new Circle(100.0f,100.0f,100.0f);
}
但是我看不到自己的圈子出现在我的输出中的任何地方.我的输出完全空白.有人可以指出我在做什么错吗?
But I don't see my circle appearing anywhere in my output. My output is completely blank. Can somebody point at what am I doing wrong?
这是我的输出窗口:
推荐答案
您的所有子类都将创建圆.它不会将其添加到任何地方的窗格中.要将其添加到窗格中,您需要在某处调用getChildren().add(...)
;例如在构造函数中:
All your subclass does it create the circle. It doesn't add it to a pane anywhere. To add it to the pane, you need to call getChildren().add(...)
somewhere; for example in the constructor:
public class SubClass extends Pane {
Circle c = new Circle(100.0f,100.0f,100.0f);
public SubClass() {
getChildren().add(c);
}
}
这篇关于JavaFX,外部类扩展窗格,将其添加到主类不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文