Source of TreeDemo.java


  1: //TreeDemo.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, int bottomWidth, int bottomHeight)
 20:     {
 21:         System.out.println("       Save the Redwoods!");
 22:         TriangleInterface treeTop = new Triangle(INDENT, topWidth);
 23:         drawTop(treeTop);
 24: 
 25:         RectangleInterface treeTrunk =
 26:             new Rectangle(INDENT + (topWidth / 2) - (bottomWidth / 2),
 27:                           bottomHeight, bottomWidth);
 28:         drawTrunk(treeTrunk);
 29:     }
 30: 
 31:     private static void drawTop(TriangleInterface treeTop)
 32:     {
 33:         treeTop.drawAt(1);
 34:     }
 35: 
 36:     private static void drawTrunk(RectangleInterface treeTrunk)
 37:     {
 38:         treeTrunk.drawHere(); // or treeTrunk.drawAt(0);
 39:     }
 40: }