BoebotSimGUI.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import javax.swing.*;
  2. import java.awt.event.*;
  3. import java.awt.*;
  4. import java.util.*;
  5. /**
  6. * Write a description of class BoebotSimGUI here.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class BoebotSimGUI extends JFrame
  12. {
  13. private ArrayList<ArrayList<Kruispunt>> map;
  14. private int teller = -1;
  15. private BoebotSimulator boebotSimulator;
  16. private int ox;
  17. private int oy;
  18. private int orotation;
  19. private int y;
  20. private int x;
  21. private int xx;
  22. private int xy;
  23. private int ex;
  24. private int ey;
  25. private JPanel content;
  26. private JPanel scherm;
  27. public BoebotSimGUI(BoebotSimulator boebotSimulator)
  28. {
  29. super("Boebot Simulatie");
  30. this.boebotSimulator = boebotSimulator;
  31. this.x = 10;
  32. this.y = 10;
  33. int teller = 0;
  34. scherm = new JPanel(new BorderLayout());
  35. content = new JPanel(new GridLayout(x,y));
  36. JPanel menu = new JPanel (new FlowLayout());
  37. this.ox = 0;
  38. this.oy = 0;
  39. this.orotation = 0;
  40. this.xx = boebotSimulator.geefXX();
  41. this.xy = boebotSimulator.geefXY();
  42. this.ex = boebotSimulator.geefEX();
  43. this.ey = boebotSimulator.geefEY();
  44. if(boebotSimulator.ax.size() > 0)
  45. {
  46. ox = boebotSimulator.ax.get(0);
  47. oy = boebotSimulator.ay.get(0);
  48. }
  49. map = new ArrayList<ArrayList<Kruispunt>>();
  50. for(int row = 0; row < y; row ++)
  51. {
  52. map.add(row, new ArrayList<Kruispunt>());
  53. for(int col = 0; col < x; col ++)
  54. {
  55. map.get(row).add(new Kruispunt());
  56. Kruispunt kruispunt = map.get(row).get(col);
  57. if(row == (9 - ey) && col == ex)
  58. {
  59. kruispunt.setFinish();
  60. }
  61. if(row == (9 - oy) && col == ox)
  62. {
  63. kruispunt.setBoebot(orotation);
  64. }
  65. if(row == (9 - xy) && col == xx)
  66. {
  67. kruispunt.setGat();
  68. }
  69. content.add(kruispunt);
  70. }
  71. }
  72. JButton previous = new JButton("vorige");
  73. menu.add(previous);
  74. JButton next = new JButton("volgende");
  75. menu.add(next);
  76. previous.addActionListener(new ActionListener()
  77. {
  78. public void actionPerformed(ActionEvent event)
  79. {
  80. vorigeStapBoebot();
  81. }
  82. });
  83. next.addActionListener(new ActionListener()
  84. {
  85. public void actionPerformed(ActionEvent event)
  86. {
  87. volgendeStapBoebot();
  88. }
  89. });
  90. scherm.add(content, BorderLayout.CENTER);
  91. scherm.add(menu, BorderLayout.SOUTH);
  92. setContentPane(scherm);
  93. setSize(950,700);
  94. setVisible(true);
  95. }
  96. public void vorigeStapBoebot()
  97. {
  98. if(teller > 0)
  99. {
  100. teller --;
  101. ox = boebotSimulator.ax.get(teller);
  102. oy = boebotSimulator.ay.get(teller);
  103. orotation = boebotSimulator.arotation.get(teller);
  104. refresh();
  105. }
  106. }
  107. public void volgendeStapBoebot()
  108. {
  109. if(teller < boebotSimulator.ax.size())
  110. {
  111. teller ++;
  112. ox = boebotSimulator.ax.get(teller);
  113. oy = boebotSimulator.ay.get(teller);
  114. orotation = boebotSimulator.arotation.get(teller);
  115. refresh();
  116. }
  117. }
  118. public void refresh()
  119. {
  120. content.removeAll();
  121. for(int row = 0; row < y; row ++)
  122. {
  123. map.add(row, new ArrayList<Kruispunt>());
  124. for(int col = 0; col < x; col ++)
  125. {
  126. map.get(row).add(new Kruispunt());
  127. Kruispunt kruispunt = map.get(row).get(col);
  128. if(row == (9 - ey) && col == ex)
  129. {
  130. kruispunt.setFinish();
  131. }
  132. if(row == (9 - oy) && col == ox)
  133. {
  134. kruispunt.setBoebot(orotation);
  135. }
  136. if(row == (9 - xy) && col == xx)
  137. {
  138. kruispunt.setGat();
  139. }
  140. content.add(kruispunt);
  141. }
  142. }
  143. setContentPane(scherm);
  144. }
  145. }