Kruispunt.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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("src/pictures/boebot.png"));
  31. }catch (IOException e){
  32. }
  33. }
  34. if(rotation == 0)
  35. {
  36. try{
  37. kruispunt = ImageIO.read(new File("src/pictures/boven boebot.png"));
  38. }catch (IOException e){
  39. }
  40. }
  41. if(rotation == 180)
  42. {
  43. try{
  44. kruispunt = ImageIO.read(new File("src/pictures/onder boebot.png"));
  45. }catch (IOException e){
  46. }
  47. }
  48. if(rotation == 270)
  49. {
  50. try{
  51. kruispunt = ImageIO.read(new File("src/pictures/links boebot.png"));
  52. }catch (IOException e){
  53. }
  54. }
  55. this.repaint();
  56. }
  57. public void setGat()
  58. {
  59. try{
  60. kruispunt = ImageIO.read(new File("src/pictures/gat.png"));
  61. }catch (IOException e){
  62. }
  63. this.repaint();
  64. }
  65. public void setFinish()
  66. {
  67. try{
  68. kruispunt = ImageIO.read(new File("src/pictures/finish.png"));
  69. }catch (IOException e){
  70. }
  71. this.repaint();
  72. }
  73. protected void paintComponent(Graphics g){
  74. super.paintComponent(g);
  75. Graphics2D g2 = (Graphics2D) g;
  76. g2.setStroke(new BasicStroke(3));
  77. Shape horLine = new Line2D.Double(0,getHeight()/2,getWidth(),getHeight()/2);
  78. Shape verLine = new Line2D.Double(getWidth()/2,0,getWidth()/2,getHeight());
  79. g2.draw(horLine);
  80. g2.draw(verLine);
  81. g2.drawImage(kruispunt, 0, 0, getWidth(), getHeight(), null);
  82. }
  83. }