在Java和JavaFX中使用命令行参数
我有以下代码:在Java和JavaFX中使用命令行参数,java,javafx,scenebuilder,Java,Javafx,Scenebuilder,我有以下代码: public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ Parent root = FXMLLoader.load(getClass().getResource("hive.fxml")); primaryStage.setTitle("Hive-viewer"); primary
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("hive.fxml"));
primaryStage.setTitle("Hive-viewer");
primaryStage.setScene(new Scene(root, 1600, 900));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
我想知道您将如何在控制器或主类中的方法中使用文件(通过命令行提供)Try。这将为您提供命令行参数
举个小例子(我从拉斐尔的答案中提取了主要代码)
假设控制器类名为“MyController”
您使用的是什么命令行?在这个答案中添加一些细节可能会有所帮助,并举例说明如何将从方法调用中检索到的参数值传递给控制器。@James\u感谢您的建议。我希望现在好些。我不是那么活跃,所以。
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
FXMLLoader loader=new FXMLLoader(getClass().getResource("hive.fxml"));
Parent root = loader.load();
MyController cont=load.getController();
/*
This depends on your controller and you have to decide
How your controller need the arguments
*/
cont.setParameter(getParameters());
primaryStage.setTitle("Hive-viewer");
primaryStage.setScene(new Scene(root, 1600, 900));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}