import java.awt.*; /** * A simple class to draw a simple scene * * @author Ben Dugan * @author Hal Perkins * @version 6/27/01 */ public class Scene { GWindow theWindow; // window shared by all methods in this class instance /** Create a new window and draw a pleasant scene in it */ public void drawScene( ) { // create the shared window theWindow = new GWindow( ); // draw the picture drawHouse( ); drawTree(280,260,20,100,100,100); drawTree(350,350,20,100,80,100); } /** Draw a picture of a house in the window */ public void drawHouse( ) { // Define house coordinates and dimensions int frameX = 50; // lower left x of the walls int frameY = 350; // lower left y of the walls int wallWidth = 150; int wallHeight = 100; int roofWidth = 200; int roofHeight = 50; int overhang = roofWidth - wallWidth; int roofBaseY = frameY - wallHeight; // Make the basic frame of the house theWindow.add(new Rectangle(frameX, roofBaseY, wallWidth, wallHeight)); theWindow.add(new Triangle(frameX-overhang, roofBaseY, frameX + wallWidth + overhang, roofBaseY, frameX + (wallWidth/2), roofBaseY - roofHeight, Color.red, true)); } /** Draw a tree in the garden. @param x the x coord of the center of the base of the trunk @param y the y coord of the center of the base of the trunk @param trunkWidth the width of the trunk @param trunkHeight the height of the trunk @param crownWidth the width of the crown @param crownHeight the height of the crown */ public void drawTree(int x, int y, int trunkWidth, int trunkHeight, int crownWidth, int crownHeight) { int rectHeight = trunkHeight + (crownHeight/2); theWindow.add(new Rectangle(x - trunkWidth/2, y - rectHeight, trunkWidth, rectHeight, Color.blue, true)); theWindow.add(new Oval(x - crownWidth/2, y - trunkHeight - crownHeight, crownWidth, crownHeight, Color.green, true)); } }