Question 1: Write an applet, Scribble, that responds to the mouseDown and the mouseDrag events.

Question 2: Extend your Scribble applet by adding a button at the top of the applet with the title "Erase". When you click erase, the scribble window should be cleared. You clear by filling (g.fillRect(x, y, width, height)) the applet window with the background color (getBackground()), and get the bounds of the applet screen with bounds().

Question 3: Extend your Scribble applet by adding a menu button to the applet with the entries "Default", "Red", "Yellow", and "Blue". Whenever you draw lines, the color of the line should be the color of the currently selected color in the color menu, where "Default" is the foreground color (getForeground()).

By now, your applet should look something like this:

Question 4: Imagemaps.

An imagemap is a fancy way of adding flare to your home page. An imagemap is an applet that consists of an image and some "hot spots". These hot spots are areas in the image that contain URLs to other pages of interest, like your major, resume, or soccer page.

Consider the next applet that implements an imagemap:

The source code for this applet can be found at: Lab3Map.java.
The HTML code for this applet can be found at: Lab3Map.html.
The image for this applet can be found at: lab3map.gif.

Study the source code and, using the comments in the code, try to understand what the applet does. Also look at the HTML file and try to understand it.

Now, change the program so that, instead of drawing the rectangle when you click on a hot spot with the mouse, the rectangle gets drawn when you move your mouse over the hot spot. Also, the hot spot's URL gets displayed in the statusbar when you move your mouse over a hot spot.

NOTE: you must then also remove the drawn rectangle and statusbar text when the mouse leaves a hot spot. For an example of a similar applet look at the java_labs page.

Question 5 (Extra Credit): Go to one of the VRML pages and view a 3D world. If your browser is not supporting VRML files, then you need to download a plug-in (see vrml.html for sites). If you have the latest Netscape with Live3D, then it should already work.


Java Home
Lectures
Labs
Lecture3