/**
 * RectangleComponent from slides, with experiments on drawing more than just two rectangles.
 * 
 * Lect 24, Apr 4 2006
 * 
 */
import java.awt.Graphics;   // AWT is the Abstract Windowing Toolkit,
import java.awt.Graphics2D; // an older graphical user interface
import java.awt.Rectangle;  // toolkit
import javax.swing.JPanel;
import javax.swing.JComponent;
import java.awt.Color;

public class RectangleComponent extends JComponent
{
  public void paintComponent(Graphics g)
  {
    Graphics2D g2 = (Graphics2D) g;
    Rectangle box = new Rectangle(5, 10, 50, 75);
    
    // Experiment: try drawing multiple steps along the way when moving the box.
    final int startx = 5;
    final int stopx = 80;
    final int movex = 10;
    // First try had movex=1, that created a solid block over the path since
    // each box was right up next to previous one.

    //Color myColor = new Color(1,0,0);
    // First try was wrong: float values range from 0.0 to 1.0, but int values range from 0 to 255.
    // Using RGB Color, for more on that take 314, the Intro Graphics course!

    Color myColor = new Color(255,0,0);
    g2.setColor(myColor);
    for (int x = startx; x <= stopx; x+=movex) {   
        //box.translate(x,x);
        // We've set up the for loop so that we want to set an absolute
        // location, not move relative to current position.
        
        box.setLocation(x,x);
        g2.draw(box);
    }
  }
}
