通常,除了传递给您的主程序的程序参数外,无需将参数传递给主应用程序。想要这样做的唯一原因是创建一个可重用的对象
Application。但这
Application并不需要是可重用的,因为这是组装您的应用程序的代码。认为
start方法是新的
main!
因此,与其编写
Application在
main方法中配置的可重用的应用程序,不如将应用程序本身作为配置器,并使用可重用的组件在
start方法中构建应用程序,例如:
public class MyApplication extends Application { @Override public void start(Stage stage) throws Exception { // Just on example how it could be done... Controller controller = new Controller(); MyMainComponent mainComponent = new MyMainComponent(controller); mainComponent.showIn(stage); } public static void main(String[] args) { Application.launch(args); }}


