The starting point for a JavaFX application is start method. But in the sample JavaFX applications, there is a main method included as well. What is the use of main method in this particular case and why was there a need to define start() as starting point for JavaFX. Couldn't we simply use the main method to define a starting point like Swings?
A sample HelloWorld 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);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…