Random Rectangles

Write a class named RectangleDrawer that extends a TwoButtonBreadboard. When executed, this class should prompt the user to enter some number of rectangles to draw, and then -- when the user clicks the "Go" button -- this number of rectangles should be drawn, with one rectangle drawn each 100 milliseconds. The rectangles themselves should be randomly colored red, blue, green, or yellow. The sizes of the rectangles should be randomly chosen to be somewhere between 20 and 100 pixels. The location of each rectangle should be randomly chosen to be somewhere in the central drawing area. However, each rectangle must be entirely visible in the window (i.e., there should be no rectangles "hanging off the edge of the window").

Check out the video below to see what this program should look like when you are done...


Having trouble knowing when your rectangle is vertically "in the canvas area"? Check out the code below with puts a rectangle in the canvas with a 10 pixel border:

import java.awt.Color;
import acm.breadboards.OneButtonBreadboard;
import acm.graphics.GRect;

public class AcmFun extends OneButtonBreadboard {
	public void run() {	
		int canvasHeight = this.getRegionPanel(CENTER).getHeight();
		int canvasWidth = this.getWidth();
		GRect rect = new GRect(10, 10,canvasWidth - 20,canvasHeight - 20);