public class MyMDI extends AbstractMDIApplication { public MyMDI(String[] args) { super("My MDI"); ... } @Override public URL getCommandLineConfiguration() { return this.getClass().getResource("commandline.xml"); } }
commandline.xml
arguments file:<arguments> <argument key="sizeX" type="int" /> <argument key="sizeY" type="int" /> </arguments>
public class MyMDI extends AbstractMDIApplication { private int sizeX = 200; private int sizeY = 200; public MyMDI(String[] args) { super("My MDI"); super.preparePanels(); // set the command-line arguments this.setCommandLineArguments(args); // apply the arguments for the application (it will indirectly call the handleCommandLineArguments method) super.applyCommandLineArguments(); // set the size of the Application window this.setSize(sizeX, sizeY); } @Override public URL getCommandLineConfiguration() { // specify the xml file specifying the arguments return this.getClass().getResource("commandline.xml"); } @Override public void handleCommandLineArguments(Map<String, ArgumentGroup> argumentGroups, Map<String, Argument> arguments) { // handle the arguments if (arguments.containsKey("sizeX")) { Argument arg = arguments.get("sizeX"); sizeX = (Integer)arg.getValue(); } if (arguments.containsKey("sizeY")) { Argument arg = arguments.get("sizeY"); sizeY = (Integer)arg.getValue(); } } public static void main(String[] args) { MyMDI mdi = new MyMDI(args); mdi.setVisible(true); } }We can for example start the application with:
java -jar MyMDI.jar -sizeX=800 -sizeY=300
or even with:
java -jar MyMDI.jar sizeX=800 sizeY 300
commandline.xml
arguments file:<arguments> <argument key="-sizeX" type="int" /> <argument key="-sizeY" type="int" /> </arguments>The code for the application will be almost identical to the previous example:
public class MyMDI extends AbstractMDIApplication { private int sizeX = 200; private int sizeY = 200; public MyMDI(String[] args) { super("My MDI"); super.preparePanels(); // set the command-line arguments this.setCommandLineArguments(args, true); // apply the arguments for the application (it will indirectly call the handleCommandLineArguments method) super.applyCommandLineArguments(); // set the size of the Application window this.setSize(sizeX, sizeY); } @Override public URL getCommandLineConfiguration() { // specify the xml file specifying the arguments return this.getClass().getResource("commandline.xml"); } @Override public void handleCommandLineArguments(Map<String, ArgumentGroup> argumentGroups, Map<String, Argument> arguments) { // handle the arguments if (arguments.containsKey("-sizeX")) { Argument arg = arguments.get("-sizeX"); sizeX = (Integer)arg.getValue(); } if (arguments.containsKey("-sizeY")) { Argument arg = arguments.get("-sizeY"); sizeY = (Integer)arg.getValue(); } } public static void main(String[] args) { MyMDI mdi = new MyMDI(args); mdi.setVisible(true); } }We can for example start the application with:
java -jar MyMDI.jar -sizeX=800 -sizeY=300
Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences