CPSC 124 (Fall 1998): Lab 9
More Components and Events

WELCOME TO THE NINTH LAB for Computer Science 124. For this lab, you should do the second exercise from Lab 8, which was postponed from last week. You should also do the exercise described below, which deals with component layout and event listeners. If you have any extra time in the lab, you can work on your final project. The exercises for this lab are due in class on the Monday following the lab. You should turn in Exercises 2 and 4 from Lab 8, as well as a printout of the KaleidaDraw.java file that you complete as described below.

Before you begin, copy the folder /home/cs124/lab9 into your home directory. You will be working in this directory as well as in the lab8 directory.

Laying Out an Applet

The exercise for this lab is to write the init() method of a relatively complex applet. The applet is a sketching program that can draw symmetric, "kaleidascopic" sketches. You can see the completed version by running "appletviewer KaleidaDraw.html" in the lab9 directory. You can also see it on a separate page. (Be sure to try it will all the symmetry options enabled!)

The entire source code, except for the insides of the init() method, can be found in the file KaleidaDraw.java. You need to complete this init() method, so that it lives up to its comment:

         public void init() {
              // Initialize the applet.  Create the components that the 
              // applet contains.  Lay out the applet and register the 
              // applet to listen for ActionEvents from the button and ItemEvents 
              // from drawColorChoice and from the three checkboxes.  Note that 
              // the overall layout of the applet is a BorderLayout with the 
              // canvas in the "Center" and with Panels in the "North" and
              // "South" positions to hold the other components.
         } // end init();

That's the entire exercise! Although it is not required, you might want to study the SymmetryCanvas class. It demonstrates how to use an off-screen canvas to store a backup of the image displaye by a canvas. It also shows how to respond to a mouse-drag operation.

[ Lab Index | Online Notes ]