0

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 {

    }
}
Zoltan King
  • 1,964
  • 4
  • 18
  • 38
  • 2
    When a JavaFX application is launched via `Application#launch` then a sequence of events occurs which is [documented here](https://openjfx.io/javadoc/13/javafx.graphics/javafx/application/Application.html) (under _Life-cycle_). The JavaFX runtime instantiates the specified application class via reflection and then invokes the life-cycle methods in the appropriate order at the appropriate time. What this means is that the `Stage` passed to `#start(Stage)` is created by the JavaFX runtime (i.e. by internal code) and then passed to the method when invoked. – Slaw Dec 03 '19 at 01:26

1 Answers1

0

Your class is like a Java class and is executed by a classloader. The role of this classloaser is to execute the start function by reflection, and other functions available in your class if needed. In the case of JavaFX, Stage is already instantiated as a parameter and you use it to show the Scene. So you don't have to worry about it. You can read about template design pattern and IoC, it will help you understand the principle behind.

Harry Coder
  • 2,429
  • 2
  • 28
  • 32
  • 1
    It's not just "like a" java class, it is a java class. JavaFX is just a java api, so in most cases all of your JavaFX application is implemented in java. The fact that some library is involved does not change this fact. – fabian Dec 03 '19 at 06:38
  • @fabian Of course, I know. It just for the explanation I used the `like a java class` expression. I am trying to explain it in a general purpose. – Harry Coder Dec 03 '19 at 09:41