Advertisement
Nostrada1

Untitled

Jan 7th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. /**
  2. * This class represents a simple picture. You can draw the picture using
  3. * the draw method. But wait, there's more: being an electronic picture, it
  4. * can be changed. You can set it to black-and-white display and back to
  5. * colors (only after it's been drawn, of course).
  6. *
  7. * This class was written as an early example for teaching Java with BlueJ.
  8. *
  9. * @author Michael Kölling and David J. Barnes
  10. * @version 2016.02.29
  11. */
  12. public class Picture
  13. {
  14. private Square wall;
  15. private Square window;
  16. private Triangle roof;
  17. private Circle sun;
  18. private boolean drawn;
  19. private Person dude;
  20.  
  21. /**
  22. * Constructor for objects of class Picture
  23. */
  24. public Picture()
  25. {
  26. wall = new Square();
  27. window = new Square();
  28. roof = new Triangle();
  29. sun = new Circle();
  30. dude = new Person();
  31. drawn = false;
  32. }
  33.  
  34. /**
  35. * Draw this picture.
  36. */
  37. public void draw()
  38. {
  39. if(!drawn) {
  40. dude.moveHorizontal(220);
  41. dude.moveVertical(30);
  42. dude.makeVisible();
  43.  
  44. wall.moveHorizontal(-140);
  45. wall.moveVertical(20);
  46. wall.changeSize(120);
  47. wall.makeVisible();
  48.  
  49. window.changeColor("black");
  50. window.moveHorizontal(-120);
  51. window.moveVertical(40);
  52. window.changeSize(40);
  53. window.makeVisible();
  54.  
  55. roof.changeSize(60, 180);
  56. roof.moveHorizontal(20);
  57. roof.moveVertical(-60);
  58. roof.makeVisible();
  59.  
  60. sun.changeColor("blue");
  61. sun.moveHorizontal(100);
  62. sun.moveVertical(-40);
  63. sun.changeSize(80);
  64. sun.makeVisible();
  65. drawn = true;
  66. }
  67. }
  68.  
  69. public void sunRise()
  70. {
  71. sun.slowMoveVertical(-200);
  72. drawn=true;
  73. }
  74.  
  75. public void sunSet()
  76. {
  77. sun.slowMoveVertical(200);
  78. drawn=true;
  79. }
  80.  
  81. public void dudeWalksToHouse()
  82. {
  83. dude.slowMoveHorizontal(-200);
  84. drawn=true;
  85. }
  86.  
  87. /**
  88. * Change this picture to black/white display
  89. */
  90. public void setBlackAndWhite()
  91. {
  92. wall.changeColor("black");
  93. window.changeColor("white");
  94. roof.changeColor("black");
  95. sun.changeColor("black");
  96. }
  97.  
  98. /**
  99. * Change this picture to use color display
  100. */
  101. public void setColor()
  102. {
  103. wall.changeColor("red");
  104. window.changeColor("black");
  105. roof.changeColor("green");
  106. sun.changeColor("yellow");
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement