/* Rectangle.java
*
* Bruce M. Bolden
* February 8, 1998
* http://www.cs.uidaho.edu/~bruceb/
*/
import java.awt.Color;
import java.awt.Graphics;
/** Parent class for all rectangular objects. */
public class Rectangle extends GObject
{
private int width;
private int height;
private static final int DEFAULT_SIZE = 10;
public Rectangle() {
this( 0, 0, Color.black, DEFAULT_SIZE, DEFAULT_SIZE );
}
public Rectangle(int x, int y, Color c) {
this( x, y, c, DEFAULT_SIZE, DEFAULT_SIZE );
}
public Rectangle(int x, int y, Color c, int width, int height) {
setX( x );
setY( y );
setColor( c );
this.width = width;
this.height = height;
}
/** calculates the area of a rectangular object */
public int area() {
return width * height;
}
/** writes the area to standard output stream
* Note the use of the method area() */
public void showArea() {
System.out.println( " " + area() );
}
/** writes the color to standard output stream
* Note the use of toString(). */
public void showColor() {
System.out.println( " " + c.toString() );
}
/** draw the rectangle */
public void draw( Graphics g ) {
g.setColor( getColor() );
g.drawRect( x, y, width, height );
}
}