Source of ShapeBasics.java


  1: //ShapeBasics.java

  3: /**
  4:  * Class for drawing simple shapes on the screen using keyboard
  5:  * characters. This class will draw an asterisk on the screen as a 
  6:  * test. It is not intended to create a "real" shape, but rather
  7:  * to be used as a base class for other classes of shapes.
  8: */
  9: public class ShapeBasics implements ShapeInterface
 10: {
 11:     private int offset;

 13:     public ShapeBasics()
 14:     {
 15:         offset = 0;
 16:     }

 18:     public ShapeBasics(int theOffset)
 19:     {
 20:         offset = theOffset;
 21:     }

 23:     public void setOffset(int newOffset)
 24:     {
 25:         offset = newOffset;
 26:     }

 28:     public int getOffset()
 29:     {
 30:         return offset;
 31:     }

 33:     /** Draws the shape at lineNumber lines down from the current line. */
 34:     public void drawAt(int lineNumber)
 35:     {
 36:         for (int count = 0; count < lineNumber; count++)
 37:             System.out.println( );
 38:         drawHere( );
 39:     }

 41:     /** Draws the shape at the current line. */
 42:     public void drawHere()
 43:     {
 44:         for (int count = 0; count < offset; count++)
 45:             System.out.print(' ');
 46:         System.out.println('*');
 47:     }
 48: }