/* Square.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 square objects. */
public class Square extends GObject
{
private int sideLength;
private static final int DEFAULT_SIZE = 10;
public Square() {
setX( 0 ); // default position (0, 0)
setY( 0 );
setColor( Color.black );
this.sideLength = DEFAULT_SIZE;
//this( 0, 0, Color.black, DEFAULT_SIZE );
}
public Square(int x, int y, Color c) {
this( x, y, c, DEFAULT_SIZE );
}
public Square(int x, int y, Color c, int sLength) {
setX( x );
setY( y );
setColor( c );
this.sideLength = sLength;
}
/** calculates the area of a rectangular object */
public int area() {
return sideLength * sideLength;
}
/** 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 square */
public void draw( Graphics g ) {
g.setColor( getColor() );
g.drawRect( x, y, sideLength, sideLength );
}
}