首页 > 解决方案 > How is the Stage instantiated in this JavaFX sample code?

问题描述

This is a simple JavaFX starting point.

DemoApp inherits from Application. Application has an abstract method and that needs to be implemented. That's the @Overriden one.

The thing that confuses me is the parameter of the method. It has a class type and a name. Right?

But how did the name "stage" get instantiated to create an object if there is no = new Stage();" ? It is only "Stage stage" and not "Stage stage = new Stage();"

public class DemoApp extends Application {
    @Override
    public void start(Stage stage) throws Exception {

    }
}

标签: javajavafx

解决方案


class就像一个 Javaclass并且由一个类加载器执行。这个 classloaser 的作用是start通过反射class执行函数,如果需要,还可以使用其他可用的函数。在 JavaFX 的情况下,Stage已经实例化为参数,您可以使用它来显示Scene. 所以你不必担心。您可以阅读有关模板设计模式和IoC的内容,它将帮助您了解背后的原理。


推荐阅读