Mystery


Your browser is ignoring the <APPLET> tag!

This mystery program draws randomly sized rectangles at random locations and with random colors. New rectangles continuously appear as the user moves the mouse with the mouse button up.

import objectdraw.*;
import java.awt.Color;

/**
 * @author Barbara Lerner 
 * @version October 20, 2008
 */
public class Mystery extends WindowController
{
    private static final int WINDOW_SIZE = 400;
    
    public void begin () {
        resize (WINDOW_SIZE, WINDOW_SIZE);
    }
    
    public void onMouseMove (Location point) {
        RandomIntGenerator gen1 = new RandomIntGenerator (0, WINDOW_SIZE);
        int num1 = gen1.nextValue();
        int num2 = gen1.nextValue();
        int num3 = gen1.nextValue();
        int num4 = gen1.nextValue();
        
        RandomIntGenerator gen2 = new RandomIntGenerator (0, 255);
        int num5 = gen2.nextValue();
        int num6 = gen2.nextValue();
        int num7 = gen2.nextValue();
        Color c = new Color (num5, num6, num7);
        
        FilledRect rect = new FilledRect (num1, num2, num3, num4, canvas);
        rect.setColor (c);
    }
}