Lab 16: File I/O

The goal of this lab is to practice file I/O and to review designing windows.

1. Introduction

In this lab we will revisit the Skeet program from lab 14. 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:

2. Set up

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/lab16
cd lab16

Then copy from your lab14 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 Skeet.java or Skeets.java, talk to the instructor about how to make your version work with this lab.

If you did not do the Skeet lab, copy the files from /cslab/class/csci235/lab16b/.

Remember that you will need to include -cp simulation.jar:. with both the javac and java commands.

3. Designing a protocol

First, discuss with your partner how you can save/store a collection of Skeets. You'll need to decided on a file format/protocol.

4. Writing the 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.

5. Loading a saved configuration

Finally, in the file Skeets.java, find the portion of code that will load a configuration from a file and fill-in what's missing.

6. Turn in

Turn in those source files that you changed with a command such as

/cslab/class/csci235/bin/handin lab16 *.java

Thomas VanDrunen, Cary Gray
Last modified: Thu Dec 10 07:48:48 CST 2009