Advertisement
Guest User

Oefening 6.8 Verkeerslicht class

a guest
Mar 30th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. package Oefening0608;
  2.  
  3.  
  4. import java.awt.Color;
  5. import java.awt.Graphics;
  6.  
  7. import javax.swing.*;
  8. public class Verkeerslicht {
  9.  
  10. boolean rood;
  11. boolean oranje;
  12. boolean groen;
  13.  
  14. // CONSTRUCTOR
  15. public Verkeerslicht() {
  16.  
  17. }
  18.  
  19. // SETTERS
  20. public void setRood(boolean rood) {
  21. this.rood = rood;
  22. }
  23.  
  24. public void setOranje(boolean oranje) {
  25. this.oranje = oranje;
  26. }
  27.  
  28. public void setGroen(boolean groen) {
  29. this.groen = groen;
  30. }
  31.  
  32. public void reset(){
  33.  
  34. rood = false;
  35. oranje = false;
  36. groen = false;
  37.  
  38. }
  39.  
  40. public Graphics teken(Graphics g){
  41.  
  42. g.setColor( Color.GRAY );
  43. g.fillRect(30, 10, 80, 150);
  44.  
  45. g.setColor( Color.darkGray );
  46. g.fillRect(60, 160, 20, 60);
  47.  
  48. if(rood == true){
  49. g.setColor( Color.RED );
  50. g.fillOval(50, 20, 40, 40);
  51. g.setColor( Color.LIGHT_GRAY );
  52. g.fillOval(50, 65, 40, 40);
  53. g.fillOval(50, 110, 40, 40);
  54. }else if(oranje == true){
  55. g.setColor( Color.LIGHT_GRAY );
  56. g.fillOval(50, 20, 40, 40);
  57. g.fillOval(50, 110, 40, 40);
  58. g.setColor( Color.ORANGE );
  59. g.fillOval(50, 65, 40, 40);
  60. }else if(groen == true){
  61. g.setColor( Color.LIGHT_GRAY );
  62. g.fillOval(50, 20, 40, 40);
  63. g.fillOval(50, 65, 40, 40);
  64. g.setColor( Color.GREEN );
  65. g.fillOval(50, 110, 40, 40);
  66. }else{
  67. g.fillOval(50, 20, 40, 40);
  68. g.fillOval(50, 65, 40, 40);
  69. g.fillOval(50, 110, 40, 40);
  70. }
  71. return g;
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement