我有以下代码:
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);
}
}
我想知道您将如何在Controller或Main类的方法中使用文件(通过命令行提供)
尝试getParameters。这应该给你命令行参数
希望有一个小例子(我从Raphael的答案中提取了主要代码)
假设控制器类名为“ MyController”
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);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句