package visual.statik.described;

import java.util.*;
import javax.microedition.lcdui.*;

import gui.*;

/**
 * A Canvas that renders a Rectangle with randomly
 * generated attributes each time it's paint method is called
 *
 * Changes for J2ME Version:
 *    Graphics instead of Graphics2D
 *    drawRect() instead of draw()
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0 (J2ME)
*/
public class RandomRectangleCanvas extends VisualComponent
{
    private Random        generator;
    
    
    /**
     * Default Constructor
     */
    public RandomRectangleCanvas()
    {
        super();
        generator = new Random();
    }

    
    /**
     * Render this Canvas
     *
     * @param g   The rendering engine to use
     */
    public void paint(Graphics g)
    {
       int   height, maxHeight, maxWidth, width, x, y;
        

       maxHeight = g.getClipHeight();
       maxWidth  = g.getClipWidth();

       x      = generator.nextInt(maxWidth  - 1);
       y      = generator.nextInt(maxHeight - 1);
       width  = generator.nextInt(maxWidth  - x - 1);
       height = generator.nextInt(maxHeight - y - 1);

       // Note: There is no Color class or Shape interface
       
       // Clear the screen
       g.setColor(0x00FFFFFF);
       g.fillRect(0, 0, maxWidth, maxHeight);
       
       // Draw the rectangle
       g.setColor(0x00FF00FF);
       g.drawRect(x, y, width, height);       
    }
}
