Kruispunt.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. this.repaint();
  25. }
  26. public void setBoebot(int rotation)
  27. {
  28. if(rotation == 90)
  29. {
  30. try{
  31. kruispunt = ImageIO.read(new File("src/pictures/boebot.png"));
  32. }catch (IOException e){
  33. }
  34. }
  35. if(rotation == 0)
  36. {
  37. try{
  38. kruispunt = ImageIO.read(new File("src/pictures/boven boebot.png"));
  39. }catch (IOException e){
  40. }
  41. }
  42. if(rotation == 180)
  43. {
  44. try{
  45. kruispunt = ImageIO.read(new File("src/pictures/onder boebot.png"));
  46. }catch (IOException e){
  47. }
  48. }
  49. if(rotation == 270)
  50. {
  51. try{
  52. kruispunt = ImageIO.read(new File("src/pictures/links boebot.png"));
  53. }catch (IOException e){
  54. }
  55. }
  56. this.repaint();
  57. }
  58. public void setGat(int rotation)
  59. {
  60. if(rotation == 90)
  61. {
  62. try{
  63. kruispunt = ImageIO.read(new File("src/pictures/gatrechts.png"));
  64. }catch (IOException e){
  65. }
  66. }
  67. if(rotation == 0)
  68. {
  69. try{
  70. kruispunt = ImageIO.read(new File("src/pictures/gatboven.png"));
  71. }catch (IOException e){
  72. }
  73. }
  74. if(rotation == 180)
  75. {
  76. try{
  77. kruispunt = ImageIO.read(new File("src/pictures/gatonder.png"));
  78. }catch (IOException e){
  79. }
  80. }
  81. if(rotation == 270)
  82. {
  83. try{
  84. kruispunt = ImageIO.read(new File("src/pictures/gatlinks.png"));
  85. }catch (IOException e){
  86. }
  87. }
  88. this.repaint();
  89. }
  90. public void setFinish()
  91. {
  92. try{
  93. kruispunt = ImageIO.read(new File("src/pictures/finish.png"));
  94. }catch (IOException e){
  95. }
  96. this.repaint();
  97. }
  98. protected void paintComponent(Graphics g){
  99. super.paintComponent(g);
  100. Graphics2D g2 = (Graphics2D) g;
  101. g2.setStroke(new BasicStroke(3));
  102. Shape horLine = new Line2D.Double(0,getHeight()/2,getWidth(),getHeight()/2);
  103. Shape verLine = new Line2D.Double(getWidth()/2,0,getWidth()/2,getHeight());
  104. g2.draw(horLine);
  105. g2.draw(verLine);
  106. g2.drawImage(kruispunt, 0, 0, getWidth(), getHeight(), null);
  107. }
  108. }