Kruispunt.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package customComponents;
  2. /**
  3. * Write a description of class Kruispunt here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. import java.awt.BasicStroke;
  9. import java.awt.Graphics;
  10. import java.awt.Graphics2D;
  11. import java.awt.Shape;
  12. import java.awt.geom.Line2D;
  13. import java.awt.image.BufferedImage;
  14. import java.io.File;
  15. import java.io.IOException;
  16. import javax.imageio.ImageIO;
  17. import javax.swing.JLabel;
  18. public class Kruispunt extends JLabel
  19. {
  20. BufferedImage kruispunt;
  21. public Kruispunt()
  22. {
  23. kruispunt = null;
  24. }
  25. public void setBoebot(int rotation)
  26. {
  27. if(rotation == 90)
  28. {
  29. try{
  30. kruispunt = ImageIO.read(new File("pictures/boebot.png"));
  31. }catch (IOException e){
  32. }
  33. }
  34. if(rotation == 0)
  35. {
  36. try{
  37. kruispunt = ImageIO.read(new File("pictures/boven boebot.png"));
  38. }catch (IOException e){
  39. }
  40. }
  41. if(rotation == 180)
  42. {
  43. try{
  44. kruispunt = ImageIO.read(new File("pictures/onder boebot.png"));
  45. }catch (IOException e){
  46. }
  47. }
  48. if(rotation == 270)
  49. {
  50. try{
  51. kruispunt = ImageIO.read(new File("pictures/links boebot.png"));
  52. }catch (IOException e){
  53. }
  54. }
  55. this.repaint();
  56. }
  57. public void setGat(int rotation)
  58. {
  59. if(rotation == 90)
  60. {
  61. try{
  62. kruispunt = ImageIO.read(new File("pictures/gatrechts.png"));
  63. }catch (IOException e){
  64. }
  65. }
  66. if(rotation == 0)
  67. {
  68. try{
  69. kruispunt = ImageIO.read(new File("pictures/gatboven.png"));
  70. }catch (IOException e){
  71. }
  72. }
  73. if(rotation == 180)
  74. {
  75. try{
  76. kruispunt = ImageIO.read(new File("pictures/gatonder.png"));
  77. }catch (IOException e){
  78. }
  79. }
  80. if(rotation == 270)
  81. {
  82. try{
  83. kruispunt = ImageIO.read(new File("pictures/gatlinks.png"));
  84. }catch (IOException e){
  85. }
  86. }
  87. this.repaint();
  88. }
  89. public void setFinish()
  90. {
  91. try{
  92. kruispunt = ImageIO.read(new File("pictures/finish.png"));
  93. }catch (IOException e){
  94. }
  95. this.repaint();
  96. }
  97. protected void paintComponent(Graphics g){
  98. super.paintComponent(g);
  99. Graphics2D g2 = (Graphics2D) g;
  100. g2.setStroke(new BasicStroke(3));
  101. Shape horLine = new Line2D.Double(0,getHeight()/2,getWidth(),getHeight()/2);
  102. Shape verLine = new Line2D.Double(getWidth()/2,0,getWidth()/2,getHeight());
  103. g2.draw(horLine);
  104. g2.draw(verLine);
  105. g2.drawImage(kruispunt, 0, 0, getWidth(), getHeight(), null);
  106. }
  107. }