tags:

views:

53

answers:

0

I'm trying to resize a object's height in the applet. The point of the project is to click and drag till it reaches it's max size. If you don't drag to full size it grows all till it reaches it's max height. Then it grows the petals of the flower. I keep getting a null pointer as well. I'll post the code on here as well. I really need help. It's really causing me some trouble. We can't change the flower driver.

thank you, carsen Email: [email protected]

flower code:

public class Flower extends ActiveObject{

private FilledRect stem;
private FilledOval petal1;
private FilledOval petal2;
private FilledOval center;
private static final int CENTER =50;
private Location growthClick;
private RandomIntGenerator color1 = new RandomIntGenerator(1,255);
private RandomIntGenerator color2 = new RandomIntGenerator(1,255);
private RandomIntGenerator color3 = new RandomIntGenerator(1,255);
private boolean flowerClick;
private int randomCol1=0;
private int randomCol2=0;
private int randomCol3=0;
private static final double MAX_STEM_HEIGHT=400;
private int stemHeight = 10;
private static final int DELAY_TIME=33;



public Flower(Location point, double centerxy, DrawingCanvas canvas){
    growthClick = point;
    start();
    int petalWidth=10;
    int petalHeight=15;
    stem = new FilledRect(growthClick.getX(), growthClick.getY(), 2,stemHeight, canvas);
    stem.setColor(new Color(0,255,0));
    petal1 = new FilledOval (center.getX(), center.getY(), petalHeight+10, petalWidth, canvas);
    petal2 = new FilledOval (center.getX(), center.getY(),petalWidth, petalHeight+10,  canvas);
    center = new FilledOval(growthClick, growthClick.getX(), growthClick.getY(), canvas);
    center.setColor(new Color(0,0,255));
}




public void onMouseClick(Location point){
    growthClick = point;
}

public void changeColorGenerator(){
    RandomIntGenerator colorGen = new RandomIntGenerator(0,255);
    int randomCol1 = colorGen.nextValue();
    int randomCol2 = colorGen.nextValue();
    int randomCol3 = colorGen.nextValue();}

public void changeColor(){
    if (flowerClick==true){
        petal1.setColor(new Color(randomCol1,randomCol2,randomCol3));
        petal2.setColor(new Color(randomCol1,randomCol2,randomCol3));
    }
    }

public boolean flowerContains(Location point) {
    if (petal1.contains(point) && petal2.contains(point)){
        flowerClick = true;
        return true;
    }


    else{
        flowerClick = false;}
    return false;
}{
}


public void grow(Location xy, double x, double y){

    while (stemHeight>=0);{
    if (stemHeight<=MAX_STEM_HEIGHT){
        //if (flowerClick){
        stemHeight=+20;
        //pause(DELAY_TIME);}

}}}}

flower driver:

import objectdraw.*;

// controller for Spring test program

public class Spring extends WindowController {

// The most recently created flower private Flower lastFlower;

// Create a new flower or change the color of the last flower public void onMousePress( Location point ) { if ( lastFlower != null && lastFlower.flowerContains(point) ) { lastFlower.changeColor(); } else { lastFlower = new Flower( point, canvas.getHeight()*.5, canvas ); } }

// Make the newest flower grow public void onMouseDrag( Location point ) { if ( lastFlower != null ) { lastFlower.grow(); } }

// Clear the canvas to start again when mouse move into window public void onMouseEnter(Location pt) { canvas.clear(); }

}