Source of TreeDemo.java


  1: //TreeeDemo.java
  2: 
  3: /**
  4:  * A program that draws a fir tree composed of a triangle and
  5:  * a rectangle, both drawn using keyboard characters.
  6: */
  7: public class TreeDemo
  8: {
  9:     public static final int INDENT = 5;
 10:     public static final int TREE_TOP_WIDTH = 21;// must be odd
 11:     public static final int TREE_BOTTOM_WIDTH = 4;
 12:     public static final int TREE_BOTTOM_HEIGHT = 4;
 13:         
 14:     public static void main(String[] args)
 15:     {
 16:                 drawTree(TREE_TOP_WIDTH, TREE_BOTTOM_WIDTH, TREE_BOTTOM_HEIGHT);
 17:     }
 18:         
 19:         public static void drawTree(int topWidth,
 20:         int bottomWidth,
 21:         int bottomHeight)
 22:         {
 23:         System.out.println("       Save the Redwoods!");
 24:         TriangleInterface treeTop = new Triangle(INDENT, topWidth);
 25:                 drawTop(treeTop);
 26: 
 27:         RectangleInterface treeTrunk =
 28:             new Rectangle(INDENT + (topWidth / 2) - (bottomWidth / 2),
 29:                           bottomHeight, bottomWidth);
 30:                 drawTrunk(treeTrunk);
 31:         }
 32:         
 33:         private static void drawTop(TriangleInterface treeTop)
 34:         {
 35:         treeTop.drawAt(1);
 36:         }
 37: 
 38:         private static void drawTrunk(RectangleInterface treeTrunk)
 39:         {
 40:         treeTrunk.drawHere(); // or treeTrunk.drawAt(0); 
 41:         }
 42: }
 43: