Assignment 1 - Java Warmup

Due in Lecture Jan 22

Write a Java applet that draws an "interesting" abstract picture. The picture should consist of n random shapes, drawn at random places in the applet frame. (Make n a final field - make it 10 for this assignment.) You should have at least 3 kinds of shapes, for example, rectangles, ovals, lines, or images.

Part of the purpose of this assignment is to experiment with inheritance, so define an abstract class PictureElement, with subclasses for the different kinds of shapes that you use, for example RectangleElement, OvalElement, and so forth. (We are using slightly odd names to avoid colliding with the built-in Java classes Shape and so forth.) PictureElement should include a draw method, which is overridden in the subclasses. Look at the Java Graphics interface for useful methods for drawing things; also see the Java applet example in the lecture notes, which uses Graphics as well.

For the shapes such as rectangle and oval, use Java's random number generator to give them a random size. (See java.util.Random.) If one of your shapes is ImageElement, use Random to select among multiple possible images (found on the web, from a digital camera, or whereever).

Turnin Details

For this assignment, put your applet on your personal web page. (Everyone in the department has one of these, or can create one easily -- see Creating and Modifying Home Pages.) Turn in just the hardcopy of your code; we won't use the turnin program for this assignment. Write the URL on the hardcopy, or include it in a comment, and use a yellow highlighter to make it easy to spot.

Optional Extensions

If you're an experienced Java programmer already, you may want to add some more bells and whistles -- feel free. For example, in addition to just drawing the shapes, you could animate them moving around, using threads. Or add an input capability, so that whenever the user clicks in the applet with the mouse, a new shape is drawn.

This time, we won't give extra credit for extensions -- just do these if you're interested. (The reason for not giving extra credit this time is to not give an undue advantage to the 143 Java people. We will probably have extra credit assignments later.)