- Mastering JavaFX 10
- Sergey Grinev
- 155字
- 2021-06-25 21:21:51
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
推薦閱讀
- 網絡協議工程
- Mastering Machine Learning for Penetration Testing
- C++黑客編程揭秘與防范
- Hands-On Chatbots and Conversational UI Development
- 物聯網信息安全
- Building RESTful Web Services with Spring 5(Second Edition)
- 網絡的琴弦:玩轉IP看監控
- NB-IoT物聯網技術解析與案例詳解
- Echo Quick Start Guide
- 深入理解Nginx:模塊開發與架構解析
- 數據血緣分析原理與實踐
- Laravel Application Development Cookbook
- 現場綜合化網絡運營與維護:運營商數字化轉型技術與實踐
- 區塊鏈技術與應用:打造分布式商業新生態
- Microsoft System Center 2012 Configuration Manager:Administration Cookbook