Experiments in Java


Problems for Session G1: Graphics and Applets

G1-A. A ``real'' drawing

Using Java's drawing operations, write an applet that draws a ``real'' picture (e.g., of a person, house, train, or whatever you think is appropriate). If you'd prefer to do abstract or modern art, that's okay, too.

G1-B. A parameterized face

Develop an applet that draws a face and that uses applet parameters to set the various aspects of the face (e.g., size of features, color of face).

G1-C. Rainbow text

Develop an applet that draws some text in a rainbow-like form, with the text repeated and moved in different colors.

G1-D. Repositioning the moving circle

You may have noted that the moving circle will eventually move off of the screen. Instead of moving off of the screen on the right or bottom edge, depending on the dimensions of the applet, it might be better to have the circle bounce back when it reaches an edge or wrap around to the other side. See if you can develop a mechanism for supporting either or both of these variations.

G1-E. Multiple circles

Update MovingCircleApplet so that it draws and moves multiple circles, rather than a single circle. See if you can find a way to prevent the two circles from overlapping.

G1-F. Looping circles

It is possible to use for loops to draw sequences of circles. For example,

  public void paint(Graphics paintBrush) {
    int left = 0;
    int right = 0;
    for (int i = 0; i < 10; i = i + 1) {
      paintBrush.fillOval(left,right,10,10);
      left = left + 2;
      right = right + 3;
    } // for
  } // paint()

Using a similar strategy, draw a sequence of 100 circles, changing color as you go and bouncing when you reach the edge.

Note that this is not an animation. Rather it is a still drawing that contains 100 different circles.

G1-G. Colors, revisited

We've seen two mechanisms for describing colors. We can use some built-in colors, like Color.black. We can provide red, green, and blue components. However, Java also provides other mechanisms for creating colors. Read the documentation for java.awt.Color and summarize the other possible techniques for creating colors.


Copyright (c) 1998 Samuel A. Rebelsky. All rights reserved.

Source text last modified Mon Oct 25 22:39:16 1999.

This page generated on Tue Oct 26 15:38:03 1999 by Siteweaver.

Contact our webmaster at rebelsky@math.grin.edu