Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This class represents a simple picture. You can draw the picture using
- * the draw method. But wait, there's more: being an electronic picture, it
- * can be changed. You can set it to black-and-white display and back to
- * colors (only after it's been drawn, of course).
- *
- * This class was written as an early example for teaching Java with BlueJ.
- *
- * @author Michael Kölling and David J. Barnes
- * @version 2016.02.29
- */
- public class Picture
- {
- private Square wall;
- private Square window;
- private Triangle roof;
- private Circle sun;
- private boolean drawn;
- private Person dude;
- /**
- * Constructor for objects of class Picture
- */
- public Picture()
- {
- wall = new Square();
- window = new Square();
- roof = new Triangle();
- sun = new Circle();
- dude = new Person();
- drawn = false;
- }
- /**
- * Draw this picture.
- */
- public void draw()
- {
- if(!drawn) {
- dude.moveHorizontal(220);
- dude.moveVertical(30);
- dude.makeVisible();
- wall.moveHorizontal(-140);
- wall.moveVertical(20);
- wall.changeSize(120);
- wall.makeVisible();
- window.changeColor("black");
- window.moveHorizontal(-120);
- window.moveVertical(40);
- window.changeSize(40);
- window.makeVisible();
- roof.changeSize(60, 180);
- roof.moveHorizontal(20);
- roof.moveVertical(-60);
- roof.makeVisible();
- sun.changeColor("blue");
- sun.moveHorizontal(100);
- sun.moveVertical(-40);
- sun.changeSize(80);
- sun.makeVisible();
- drawn = true;
- }
- }
- public void sunRise()
- {
- sun.slowMoveVertical(-200);
- drawn=true;
- }
- public void sunSet()
- {
- sun.slowMoveVertical(200);
- drawn=true;
- }
- public void dudeWalksToHouse()
- {
- dude.slowMoveHorizontal(-200);
- drawn=true;
- }
- /**
- * Change this picture to black/white display
- */
- public void setBlackAndWhite()
- {
- wall.changeColor("black");
- window.changeColor("white");
- roof.changeColor("black");
- sun.changeColor("black");
- }
- /**
- * Change this picture to use color display
- */
- public void setColor()
- {
- wall.changeColor("red");
- window.changeColor("black");
- roof.changeColor("green");
- sun.changeColor("yellow");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement