The goal of this lab is to practice file I/O and to review designing windows.
In this lab we will revisit the Sprite program from lab 17. This time we will give the program the facility to save the current state of the simulation and reload it later.
The program should work as before but with two changes:
Follow these set-up instructions carefully.
Make a directory for this lab and cd
into it.
First, copy files from the course directory for this lab:
hg clone /cslab/class/csci235/lab19 cd lab19
Then copy from your lab17 directory
AddListener.java
and any other class that
you wrote (you should have written another action listener,
perhaps named something like OkListener.java
.
If you previously modified either Sprite.java
or
Sprites.java
, talk to the instructor about how to make
your version work with this lab.
If you did not do the Sprite lab, copy the files from
/cslab/class/csci235/lab19b/
.
Remember that you will need to include -cp
simulation.jar:.
with both the javac
and
java
commands.
First, discuss with your partner how you can save/store a collection of Sprites. You'll need to decided on a file format/protocol.
SaveListener
Next, finish the SaveListener
class
so that its actionPerformed()
method
puts up a window asking for a filename.
This window should also have a button labelled "Ok" or
the equivalent.
Then write another action listener class which will close that window and do the actual saving.
Finally, in the file Sprites.java
, find the
portion of code that will load a configuration from a file
and fill-in what's missing.
Turn in those source files that you changed with a command such as
/cslab/class/csci235/bin/handin lab19 *.java