The methods outside the main method are not mentioned in main method.
The main method only contain launch(args);
I thought it need to call the methods outside the method that make it work in the program?
So how does launch(args)
work?
The Java launcher loads and initializes the specified Application class on the JavaFX Application Thread. If there is no main method in the Application class, or if the main method calls Application. launch(), then an instance of the Application is then constructed on the JavaFX Application Thread.
In the main method, you have to launch the application using the launch() method. This method internally calls the start() method of the Application class as shown in the following program. Prepare a scene graph with the required nodes.
An instance of the application class is created. Init() method is called. The start() method is called. The launcher waits for the application to finish and calls the stop() method.
You can actually launch a JavaFX application without a main() method.
If you open a template of JavaFX in Netbeans it have a JavaDoc explaining it:
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
So essentially, it shouldn't even be called as it is JavaFX, however if it is called then it will just pass the command line arguments (args) to the javafx.application.Application.launch which will open the JavaFX as expected.
In case you are still wondering how does the launch works, then you probably should check its source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With