(L)oad / (S)ave
Load (and save, too, of course) prompts for input of a filename, saving the current
graphics (or loading previously saved graphics). The data should be written to a TEXTFILE,
containing one graphic object per row, giving the type and all necessary informations.
The elements should therefore be shown in the file as:
Many words, a single task:
Exchange the datastructure of 'theList' from 'GraphicObject[]' to 'Vector'. This of course includes changes
wherever the array was used.
Since i do NOT want you to change anything in the 'GraphicsEngine' class, i'll provide a version that works
with both, Array and Vector. You just have to call the constructor with the Vector, instead of the Array (do
you see an advantage of Object Oriented Programming, especially information hiding here ?).
The sources contain the FULL SOLUTION to assignment 5 plus some framework and utility methods needed for
assignment 6.
I just decided to provide most of the framework: GraphicsControl is more or less complete, you just have
to add some lines in the methods 'save' and 'load', 'load' is nearly complete.
Additionally, the class 'Circle' is complete, you can use it as an example for the things to add in the classes
Rectangle and Line.
Complete these tasks first using the old array structure. When everything is complete, move on and change
the array to a Vector.
Do NOT use your own version of assignment 5 unless you really know what's going on.
Do NOT use old versions of the classes mixed with the new versions provided.
The sources are HERE.
(this information is now a little outdated, since the framework coming with the extended assignment shows you directly what to do. Nevertheless: read it, redundancy is often needed in the learning process)
SAVE:
For each class (Rectangle/Circle/Line) override the method 'toString()' (why overriding ? where is it defined ?).
'toString()' must return the object's properties in a single string, containing the data in the way described above.
Modify 'GraphicsControl' to save the array 'theList[ ]' by converting each object in the list to a string, save
each string as a single line in the text file you must have previously opened.
LOAD:
Open a previously saved text file, containing the graphics data in the way described above.
For each line, read the object type (rectangle/circle/line), and create an object by calling a newly
designed constructor, that takes a string as input. This string is exactly the line read from the file, it contains
all data necessary to create a unique object.
Again: for each class (rectabgle/circle/line), you have to create a new constructor, taking the information string
as input.
The GraphicsControl module has to decide which object to construct, hence it has to read a single line
from the file, check for the desired object type (given by its name as the first parameter in the line), and then
call the specific constructor. The class to be utilized here is the StringTokenizer.
Do not forget to catch fileformat errors ! The user could try to open an arbitrary file, containing no meaningful data to your program at all. Catch that case and inform the user !