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( ); drawLeftTree( ); drawRightTree( ); } /** 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 the garden's left tree. */ public void drawLeftTree() { int x = 270; int y = 150; int width = 20; int height = 100; int circleDiameter = 100; theWindow.add(new Rectangle(x, y, width, height, Color.blue, true)); theWindow.add(new Oval(x - (circleDiameter-width)/2, y - circleDiameter/2, circleDiameter, circleDiameter, Color.green, true)); } /** Draw the garden's right tree. */ public void drawRightTree() { int x = 340; int y = 250; int width = 20; int height = 100; int circleDiameter = 100; theWindow.add(new Rectangle(x, y, width, height, Color.blue, true)); theWindow.add(new Oval(x - (circleDiameter-width)/2, y - circleDiameter/2, circleDiameter, circleDiameter, Color.green, true)); } }