-2
public static void main(String[] args) throws FileNotFoundException, SVGFormatException {
    SVG svg = new SVG("test.svg"); //so that the file called test.svg can be called upon
    PortablePixmap ppm = new PortablePixmap(500, 500); //select the size of the pixmap(canvas)

    svg.drawPixmap(ppm); //draw on ppm

    ppm.writeToFile("out.ppm"); //save the file as out.ppm file 

This is the code I wrote, but I need to get these values from the command line input because if I hard code like this, the user cannot select what values they want to use. Can you please help me how to get these values from command line input?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332

2 Answers2

0

Command-line arguments are already available to you as the String [] passed to your main() method.

So, if you run your program as

java YourProgram test.svg out.ppm

You can access these arguments as

public static void main(String[] args) throws FileNotFoundException, SVGFormatException {
    SVG svg = new SVG(args[0]); // test.svg
    PortablePixmap ppm = new PortablePixmap(500, 500);

    svg.drawPixmap(ppm); //draw on ppm

    ppm.writeToFile(args[1]); // out.ppm
}

Since, you're using Eclipse you would have to go to

Right-click > Run As > Run configurations > Arguments tab

Add test.svg out.ppm under Program arguments. Click Apply and then Run.

Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
0

Click the little arrow next to the Run button and select run configurations -> (x) = arguments tab and below the Program arguments: text box click the variables button and have at it.

The next time you run your program, a dialog box will prompt you for the arguments.

Now, within your program, you can handle these arguments by parsing the String[] args parameter of the main method.

scottysseus
  • 1,922
  • 3
  • 25
  • 50