Source of ShapeBasics.java


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

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

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

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

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

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

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