import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;

/**
 * Class ColoredRectangle extends Rectangle to print a colored box.
 *
 * @author McKinley
 * @version April 2007
 *
 */
public class ColoredRectangle extends Rectangle {
    protected static String name = "Colored Rectangle";
    private Color myColor;

    public ColoredRectangle() {
        super();  // not required, since parameters match in the super
                  // class and thus this call is implicity, but clearer to specify
        myColor = Color.red;
    }

    public ColoredRectangle(int w, int h) {
        super(w, h);  // not required, since parameters match in the super
                      // class and thus this call is implicity, but clearer to specify
        myColor = Color.blue;
    }

    public ColoredRectangle(int w, int h, Color c) {
        super(w, h);
        myColor = c;
    }
    public void setColor(Color c) {
        myColor = c;
    }
    public Color getColor() {
        return myColor;
    }
    public void draw(DrawingBox box, int x, int y) {
        box.setColor(myColor);
        box.fillRect(x, y, width, height);  // protected lets us access these 
                                            // instance variables directly in the
                                            // subclass
    }
    public String toString() {
        return ("ColorledRectangle.toString(): " + width + " width by " + height + 
                " height " + name + " color " + myColor.getRGB() );
    }

    public static void main (String [] args)
    {
        DrawingBox box = new DrawingBox();
        
        Rectangle colorless = new Rectangle(100, 50);
        System.out.println("Rectangle colorless:\n    " + colorless);

        if (colorless instanceof Rectangle) {
            System.out.println("colorless is the super type.");
        }
        if (colorless instanceof ColoredRectangle) {
            System.out.println("colorless is the sub type.");   
        }
        
        Rectangle r = new ColoredRectangle(250,150,Color.pink);
        System.out.println("Rectangle r:\n    " + r);
        
        if (r instanceof Rectangle) {
            System.out.println("is the super type.");
        }
        if (r instanceof ColoredRectangle) {
            System.out.println("is the sub type.");   
        }
        ColoredRectangle r2 = new ColoredRectangle(250,200);
        System.out.println("ColoredRectangle r2:\n    " + r2);
        
        if (r2 instanceof Rectangle) {
            System.out.println("r2 is the super type.");
        }
        if (r2 instanceof ColoredRectangle) {
            System.out.println("r2 iss the sub type.");   
        }
    
        r.draw(box, 10, 10);
        colorless.draw(box, 10, 300);
        r2.draw(box, 300,300);

    }
}
