This lab serves as an introduction to writing Java applets. First, make a directory for this lab. As usual, mail me your lab work as a text file when you're done. 1) In ~lorenz/cs35-2/lab6/ you'll find java code for a very simple "paint" program called Scribble.java Copy this file and the file applet.html into your directory. Compile Sribble.java and load applet.html into "hotjava". (Note: compilation will give a warning; ignore it.) 2) Read and study the code so that you have a sense of how it works. The applet consists entirely of applet specific methods: init, mouseDown, mouseDrag, and action. Read about the first in http://www.javasoft.com/products/jdk/1.1/docs/api/java.applet.Applet.html and the other three in http://www.javasoft.com/products/jdk/1.1/docs/api/java.awt.Component.html Where are the Applet and Component classes in relation to one another in the class hierarchy? 3) The program uses a series of nested if-then-else statements to set a color. Create a class called ColorPair: class ColorPair { String name; Color col; } that associates a string with a color variable. Create an array of ColorPair and initialize it with the program's four colors. You can find additional colors in: http://www.javasoft.com/products/jdk/1.1/docs/api/java.awt.Color.html Modify the program to loop through the array matching the event's obj variable to the strings in each ColorPair. (What kind of search is this? Why is it OK to use it here? In search terminology, which ColorPair field is the key and which is the value?) Test your code. 4) Add an erase_button to the program. Label the button something like: "Toggle Erase". Test your code before hooking the button's action to anything. A button that does nothing should appear. 5) Add a boolean variable to the program called "erase" that's initialized to false. Add code to toggle the state of this variable when the button is pressed. 6) Modify the code in mouseDrag to draw in the background color if erase==true (thereby erasing color scribbles); otherwise, it should use the current color to draw (as it already does). See the "action" method for code that gets the background color. Test your program. You should be able to erase scribbles now. (The "eraser" is not very wide, so you need to look closely.) 7) Improve your eraser by drawing a filled circle at current x/y position. See java.awt.Graphics.fillOval in: http://www.javasoft.com/products/jdk/1.1/docs/api/java.awt.Graphics.html 8) Experiment with using filled circles to make circles when erase==false. What happens if you move the mouse quickly? 9) Add a menu to select the size of the circle to use for drawing and erasing. 10) Add a button to provide a "rectangle mode." When in this mode, and a "mouseUp" (method signature similar to "mouseDown") occurs, draw a rectangle with corners at last_x/last_y and x/y.