Java Q&A
by Steve Ball and John Miller Crawford


Listing One
class Plane {
    static int displayMode;
    static double scaleFactor;
    static double rotation, elevation;
}

Listing Two
class WebCAD extends Applet {
    WebCAD() {
        cubes[0] = new Cube(displayMode, scaleFactor, rotation,
            elevation, /*other args*/);
        ...
    }
}
class Cube {
    Cube(int displayMode, double scaleFactor, double rotation,
            double elevation, /*other args*/) {
        topFace = new Plane(displayMode, scaleFactor, rotation,
            elevation, /*other args*/);
        ...
    }
}

Listing Three
class WebCAD extends Applet {
    WebCAD() {
        cubes[0] = new Cube(this, /*other args*/);
        ...
    }
}
class Cube {
    Cube(Applet applet, /*other args*/) {
        topFace = new Plane(applet, /*other args*/);
        ...
    }
}
class Plane {
    Plane(Applet applet, /*other args*/) {
        this.applet = (WebCAD) applet;
        ...
    }
    void draw(Graphics g) {
        switch (applet.displayMode) {
            case DM_WIRE_FRAME:
            case DM_SOLID_OBJECT:
        }
    }
    private WebCAD applet;
}


Listing Four
class PlaneProperties {
    int displayMode;
    double scaleFactor;
    double rotation;
    double elevation;

    PlaneProperties(int displayMode, double scaleFactor,
            double rotation, double elevation) {
        this.displayMode = displayMode;
        this.scaleFactor = scaleFactor;
        this.rotation = rotation;
        this.elevation = elevation;
    }
}
class WebCAD extends Applet {
    WebCAD() {
        planeProperties = new PlaneProperties(Plane.DM_WIRE_FRAME,
            1.0, INITIAL_ROTATION, INITIAL_ELEVATION);
        cubes[0] = new Cube(planeProperties, /*other args*/);
    }
    private PlaneProperties planeProperties;
}


Listing Five
class Cube {
    Cube(PlaneProperties planeProperties, /*other args*/) {
        topFace = new Plane(planeProperties, /*other args*/);
        ...
    }
}

Listing Six
class Plane {
    Plane(PlaneProperties planeProperties, /*other args*/) {
        this.planeProperties = planeProperties;
        ...
    }
    void draw(Graphics g) {
        switch (planeProperties.displayMode) {
            case DM_WIRE_FRAME:
            case DM_SOLID_OBJECT:
        }
    }
    private PlaneProperties planeProperties;
}



1


