0
簡單地說,我想知道是否可以有參數接受選項或不接受選項。這對列表很有用。例如:-a
將列出可能的選項,而-a stuff
將使用這些東西來做事情。Apache Commons CLI允許參數選項或無參數選項
這裏是我當前的代碼:
options.addOption("f", "look-and-feel", false, "This sets the look and feel.");
//Some stuff happens here
if (cmd.hasOption('f')) {
String laf = cmd.getOptionValue('f');
System.out.println(laf);
if (laf == null) {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
System.out.println(info.getClassName());
}
return;
} else {
setLookAndFeel(laf);
}
} else {
setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}
鍵入-f
列表的外觀和感覺正確,同時指定其-f com.laf.LookAndFeel
還列出了它。有任何想法嗎?
我添加的代碼我使用預期不起作用。 – 2014-11-05 17:56:38