Nostrada1

1.17

Jan 7th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 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 Circle sun2;
  19. private boolean drawn;
  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. sun2 = new Circle();
  31. drawn = false;
  32. }
  33.  
  34. /**
  35. * Draw this picture.
  36. */
  37. public void draw()
  38. {
  39. if(!drawn) {
  40. wall.moveHorizontal(-140);
  41. wall.moveVertical(20);
  42. wall.changeSize(120);
  43. wall.makeVisible();
  44.  
  45. window.changeColor("black");
  46. window.moveHorizontal(-120);
  47. window.moveVertical(40);
  48. window.changeSize(40);
  49. window.makeVisible();
  50.  
  51. roof.changeSize(60, 180);
  52. roof.moveHorizontal(20);
  53. roof.moveVertical(-60);
  54. roof.makeVisible();
  55.  
  56. sun2.changeColor("red");
  57. sun2.moveHorizontal(-100);
  58. sun2.moveVertical(-40);
  59. sun2.changeSize(80);
  60. sun2.makeVisible();
  61.  
  62. sun.changeColor("blue");
  63. sun.moveHorizontal(100);
  64. sun.moveVertical(-40);
  65. sun.changeSize(80);
  66. sun.makeVisible();
  67. drawn = true;
  68. }
  69. }
  70.  
  71. /**
  72. * Change this picture to black/white display
  73. */
  74. public void setBlackAndWhite()
  75. {
  76. wall.changeColor("black");
  77. window.changeColor("white");
  78. roof.changeColor("black");
  79. sun.changeColor("black");
  80. }
  81.  
  82. /**
  83. * Change this picture to use color display
  84. */
  85. public void setColor()
  86. {
  87. wall.changeColor("red");
  88. window.changeColor("black");
  89. roof.changeColor("green");
  90. sun.changeColor("yellow");
  91. }
  92. }
Add Comment
Please, Sign In to add comment