官术网_书友最值得收藏!

Managing command-line parameters

Unlike the regular Java programs, which receive all parameters in the main(String[] args) method, JavaFX provides an extra API to get them: Application.getParameters(). Then, you can access them next categories:

  • raw format: without any changes
  • parsed named pairs: only parameters which were formatted as Java options: --name=value. They will be automatically built into a name-value map.
  • unnamed: parameters which didn't fit into the previous category.

Let's compile and run a program with next demo parameters (run these commands from Chapter1/src folder of book's GitHub repository):

javac FXParams.java
java FXParams --param1=value1 uparam2 --param3=value3

This will run next code, see the corresponding API calls in bold:

// FXParams.java
System.out.println("== Raw ==");
getParameters().getRaw().forEach(System.out::println);
System.out.println("== Unnamed ==");
getParameters().getUnnamed().forEach(System.out::println);
System.out.println("== Named ==");
getParameters().getNamed().forEach((p, v) -> { System.out.println(p + "=" +v);});

JavaFX will parse these parameters and allocated them into categories:

== Raw ==
--param1=value1
uparam
--param3=value 3
== Unnamed ==
uparam
== Named ==
param3=value 3
param1=value1
主站蜘蛛池模板: 尚志市| 卢龙县| 乌恰县| 和平县| 青神县| 潼关县| 县级市| 台东县| 临洮县| 南城县| 安国市| 乳源| 长白| 西畴县| 乐都县| 淮南市| 道真| 凯里市| 金沙县| 繁昌县| 汉阴县| 古交市| 江北区| 富川| 敖汉旗| 库尔勒市| 彭州市| 广灵县| 旌德县| 陵水| 玉林市| 麟游县| 会宁县| 柘城县| 东山县| 贵溪市| 龙川县| 周宁县| 临湘市| 宜都市| 石嘴山市|