import objectdraw.*;import java.applet.AudioClip;import java.awt.*;public class Tree extends ActiveObject {    // # of leaves to generate    private static final int NUM_LEAVES = 150;        // the canvas    private DrawingCanvas aCanvas;             // pictures of a leaf    private Image leafPic;         // for the cow    private Image upsideDownCow, cow;    private AudioClip moo;                // Dimensions of screen    private int aScreenWidth, aScreenHeight;        // used to generate random speeds and positions for leaves    private RandomIntGenerator leafLocGen;        // used to generate random speeds and positions for leaves    private RandomDoubleGenerator leafSpeedGen;        // Remember parameters and create random number generators    // in order to create leaves     public Tree(            Image leafPic,            Image cow,            Image upsideCow,            AudioClip moo,            int aScreenWidth,            int aScreenHeight,            DrawingCanvas aCanvas) {                // save the parameters for the "run" method        this.aCanvas = aCanvas;        this.leafPic = leafPic;                upsideDownCow = upsideCow;        this.cow = cow;        this.moo = moo;                this.aScreenWidth = aScreenWidth;        this.aScreenHeight = aScreenHeight;                leafLocGen = new RandomIntGenerator( 0, aScreenWidth);        leafSpeedGen = new RandomDoubleGenerator( 2, 5);                start();    }        // Successively create leaves which will fall     // to ground    public void run() {        RandomIntGenerator picker = new RandomIntGenerator(0,3);        for (int treeCount = 0;                treeCount < NUM_LEAVES;        treeCount++) {            // create a leaf            int next = picker.nextValue();            if (next == 0) {                new FallingLeaf( aCanvas, leafPic,                                 leafLocGen.nextValue(),   // x coordinate                                 leafSpeedGen.nextValue(), // y speed                                 aScreenHeight);            } else if (next == 1) {                new FallingSleet(aCanvas,                                 leafLocGen.nextValue(),                                    leafSpeedGen.nextValue() * 2,                                  aScreenHeight);            } else if (next == 2){                new FallingTomato(aCanvas,                                  leafLocGen.nextValue(),                                     leafSpeedGen.nextValue() * 2,                                   aScreenHeight);            } else {                new FallingCow(                               aCanvas,                               upsideDownCow,                               cow,                               moo,                               leafLocGen.nextValue()-50,                               aScreenHeight);            }            pause( 900);                    }    }}
