Step 1
Write a method that accepts a file name (String), an object name (String) and a DrawObj. If the DrawObj is a Rect, Oval, or Line
write out the commands from project 6 that will generate this object. For example
DrawObj aBox=new Rect(0,1,2,5);
aBox.setFillColor(Color.RED);
writeObj("myObjFile.txt", "redBox",aBox);
Might write the following to the file "myObjFile.txt"
box redBox 0 1 2 5
fill redBox 1 0 0
width redBox 0.1
line redBox 0.5 0.5 0.5
If the DrawObj is a Group, then you should write out all of the children of the group.
You only need to account for the fill color, line color, line width, translation, scale and rotation of the object. Any object other than a Rect, Oval, or Line should throw an exception and not write out anything.
Step 2
Add the command file to the command line code from project 6. This command will ask the user for a file name and will read commands from the file instead of from System.in. After reading all of the commands from the file and executing them as you did in project 6, you should again begin reading commands from the user through System.in. See the hints for how to ask the user for a file name. This should only read from .txt files. You can create .txt files either using the method from step 1 or using NotePad (in the Accessories folder for Starting programs).
Step 3
Add the command write objectName to the command line code from project 6.
This will pop up a file dialog and ask the user where they want to write to.
The named object will then be written out to the specified file (see helpful code below).
|