class Paint{ public static void main(String [] args)throws Exception{ FileWriter fileWriter = new FileWriter( args[0] ); out = new PrintWriter( fileWriter ); int dimen = Integer.parseInt( args[1] ); Paint paint = new Paint(); paint.open(dimen,dimen); dimen /= 2; int originX = dimen, originY = dimen; for(; dimen > 0; dimen -= 3){ String red = random255(); String green = random255(); String blue = random255(); paint.setColor( "#" + red + green + blue ); paint.rect(originX-dimen,originY-dimen,dimen*2,dimen*2); } paint.close(); out.close(); } }
-_-_-
An execution of the program with the command ‘java Paint fig.svg 300’
should produce an outcome similar to the following one (with possibly other
randomly chosen colors).
Background information. SVG is a standard defined at http://www.w3.org/TR/SVG11/
for placing pictures on the web. The following example demonstrates the SVG
features required for the assignment.
Submit your source file ‘Paint.java’ with the ‘submit c214aa lab7Paint.java’ command.
A command similar to ‘xmllint -format fig.svg’ can be employed to
verify that the mentioned file is well structured.
To view the figure
Place the file in your ~/WWW directory: ‘cp fig.svg ~/WWW/.’.
Provide public access to the file: ‘chmod 644 ~/WWW/fig.svg’.
Open the following file with Mozilla Firefox.
http://www.cse.ohio-state.edu/~username/fig.svg
If questions in an email of yours refer to a program you wrote, please don’t
include the program in the email. Instead, put the program in your WWW
directory with an extension .txt added to the file name (e.g., Foo.java.txt),
change the access mode of the program to 644, and provide just the file name in
the email.
Suggestion. Build your program incrementally in the following manner.
For a start, add the missing fields and methods so that the program will
compile and execute flawlesly, disregarding the kind of output it generates.
Provide to one method at a time the needed implementation of the body.
In particular,
The open(...) method may contribute the front part of the SVG
file until, but not including, the <rect> elements.
The close() method may the back part </g></svg> of the file.
The rect(...) method may contribute a <rect> element to the
output.