import uwcse.graphics.*; import java.awt.Color; /** * A picture (to illustrate the use of several classes) */ public class FunnyPicture { // The graphics window to display the picture private GWindow window; // Two smiling faces // (make them instance variables since they are accessed in // several methods) private SmilingFace face1; private SmilingFace face2; private PineTree tree1; private PineTree tree2; public FunnyPicture() { // Create the graphics window this.window = new GWindow("Funny picture", 300, 300); // Terminate the application when the user closes the window this.window.setExitOnClose(); // Background Rectangle bng = new Rectangle(0, 0, this.window.getWindowWidth(), this.window.getWindowHeight(), Color.cyan, true); this.window.add(bng); // Draw the picture this.face1 = new SmilingFace(100, 100, 0.5, this.window); this.face2 = new SmilingFace(200, 200, 1.5, this.window); this.tree1 = new PineTree(50, 150, this.window); this.tree2 = new PineTree(250, 150, this.window); } /** * Moves the faces and changes the trees' colors on the picture */ public void animatePicture() { int count = 1; // Move down and to the right while (count <= 100) { this.face1.moveBy(1, 1); this.face2.moveBy(1, 1); this.tree1.flipColor(); // Wait for 100 ms try { Thread.sleep(100); } catch (InterruptedException e) { } count++; } // Move the faces back to where they originally were while (count <= 200) { this.face1.moveBy(-1, -1); this.face2.moveBy(-1, -1); this.tree2.flipColor(); // Wait for 100 ms try { Thread.sleep(100); } catch (InterruptedException e) { } count++; } } /** * Starts the application */ public static void main(String[] args) { new FunnyPicture().animatePicture(); } }