javafx main 方法launch(args) 是如何工作的?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25070863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:33:19  来源:igfitidea点击:

how does javafx main method launch(args) work?

javajavafxjavafx-2javafx-8

提问by user2709845

The methods outside the main method are not mentioned in main method. The main method only contain launch(args);

main方法之外的方法在main方法中没有提到。主要方法只包含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?

那么如何launch(args)工作呢?

采纳答案by Mansueli

If you open a template of JavaFX in Netbeans it have a JavaDoc explaining it:

如果您在 Netbeans 中打开 JavaFX 模板,它会有一个 JavaDoc 解释它:

/**
 * 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 calledas 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.

所以本质上,它甚至不应该像JavaFX那样被调用,但是如果它被调用,那么它只会将命令行参数(args)传递给javafx.application.Application.launch,它将按预期打开JavaFX。

In case you are still wondering how does the launch works, then you probably should check its source code.

如果您仍然想知道启动是如何工作的,那么您可能应该检查它的源代码