CSCI 161: Introduction to Programming I
Spring 2007
Lab 4: Easter Rabbit (Applets and Using Classes)

Due Thurs., March 1st at beginning of class


Overview

Write an applet that draws an Easter Bunny (in anticipation of spring), at least two eggs, and an appropriate greeting. Use the Color class to make the eggs random shades of blue and orange (see the hints). Use at least the following Graphics methods: fill or drawOval, fill or drawArc, drawLine, and drawString.

 

Input Specification

No input is required.

 

Output Specification

Draw an Easter Bunny and at least two eggs, one a shade of orange, the other a shade of blue. Feel free to introduce multiple colors, but use at least the random shades. Draw a greeting as well using drawString. Remember to set the background color.

The following code draws the string "Hello" at (50, 100):
page.drawString ("Hello", 50, 100);

 

You can change the default font. Whatever font you choose, make sure it renders correctly on the lab machines (Linux has different fonts than Windows XP).

page.setFont (fontObject); will set the font for the graphics object.

 

Required Methods

Graphics: fillOval (or drawOval), fillArc (or drawArc), drawLine, and drawString

Random:   nextInt

 

Hints

Launch your project as an applet by creating a Java Applet run configuration under "Run...". Under Parameters, set the width and height large enough to accommodate your drawing.

 

Listing 2.11 in the text draws a snowman.

 

RGB triples of the form (255, x, 0), where x is between 65 and 165 (inclusive), generate shades of orange. Triples of the form (x, y, 255), where x is between 0 and 135, inclusive, and y is between 0 and 190, inclusive, generate shades of blue. Feel free to experiment; you're the artist. The site Color Numbers will help you select colors.

 

See the file Snowman.html for a sample HTML page that loads an applet. If you modify the file to load your applet, and import the HTML file into your project, you can view your applet running in a web browser. Simply run a browser and open the modified HTML page.

 

For a complete list of all the draw and fill methods, see Class Graphics.