Why is the main method used in a JavaFX application when start () already exists

The starting point for a JavaFX application is the launch method. But in JavaFX application examples, there is also a basic method. What is the use of the main method in this particular case and why did it become necessary to define start () as the starting point for JavaFX. Could we just use a basic method to determine the starting point, such as Swings?

HelloWorld sample application:

public class HelloWorld extends Application { @Override public void start(Stage primaryStage) { Button btn = new Button("Hello World"); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); StackPane root = new StackPane(); root.getChildren().add(btn); Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } 
+7
java
source share
1 answer

From Oracle Docs ,

The main () method is not required for JavaFX applications when the JAR file for the application is created using the JavaFX Packager tool, which embeds the JavaFX Launcher in the JAR file. However, it is useful to include the main () method so that you can run JAR files that were created without starting the JavaFX Launcher, for example, when using the IDE, in which the JavaFX tools are not fully integrated. In addition, Swing applications that embed JavaFX code require the main () method.

+11
source share

All Articles