//********************************************************************
//  Boxes.java       Author: Lewis and Loftus
//  
//  Demonstrates the use of conditionals and loops to guide drawing.
//********************************************************************

import java.applet.Applet;
import java.awt.*;

public class Boxes extends Applet
{
   private final int NUM_BOXES = 50;
   private final int THICKNESS = 5;
   private final int MAX_SIDE = 50;
   private final int MAX_X = 350;
   private final int MAX_Y = 250;

   //-----------------------------------------------------------------
   //  Paints boxes of random width and height in a random location.
   //  Narrow or short boxes are highlighted with a fill color.
   //-----------------------------------------------------------------
   public void paint(Graphics page)
   {
      int x, y, width, height;

      setBackground (Color.black);

      for (int count = 0; count < NUM_BOXES; count++)
      {
         x = (int) (Math.random() * MAX_X);
         y = (int) (Math.random() * MAX_Y);

         width = (int) (Math.random() * MAX_SIDE);
         height = (int) (Math.random() * MAX_SIDE);

         if (width <= THICKNESS)  // check for narrow box
         {
            page.setColor (Color.yellow);
            page.fillRect (x, y, width, height);
         }
         else
            if (height <= THICKNESS)  // check for short box
            {
               page.setColor (Color.green);
               page.fillRect (x, y, width, height);
            }
            else
            {
               page.setColor (Color.white);
               page.drawRect (x, y, width, height);
            }
      }
   }
}
