BoebotGUI.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import javax.swing.*;
  2. import java.awt.event.*;
  3. /**
  4. * Write a description of class BoebotGUI here.
  5. *
  6. * @author (your name)
  7. * @version (a version number or a date)
  8. */
  9. public class BoebotGUI extends JFrame
  10. {
  11. private Routeplanner routeplanner;
  12. private BoebotSimulator boebotSimulator;
  13. private BoebotSimGUI boebotSimGUI;
  14. private int intx;
  15. private int inty;
  16. private int intbx;
  17. private int intby;
  18. public BoebotGUI()
  19. {
  20. super("Brobot GUI");
  21. setDefaultCloseOperation(EXIT_ON_CLOSE);
  22. JPanel content = new JPanel(null);
  23. final Routeplanner routeplanner = new Routeplanner(10,10);
  24. final BoebotSimulator boebotSimulator = new BoebotSimulator(0,0,0);
  25. JButton addButton = new JButton("geefRoute");
  26. content.add(addButton);
  27. JButton startSimulatie = new JButton("testRoute");
  28. content.add(startSimulatie);
  29. JButton object = new JButton("plaats object");
  30. content.add(object);
  31. JButton popup = new JButton("Boebot Simulatie");
  32. content.add(popup);
  33. final JLabel coordinaten = new JLabel("Coördinaten van Boebot");
  34. content.add(coordinaten);
  35. final JLabel begin = new JLabel("begin");
  36. content.add(begin);
  37. final JLabel eind = new JLabel("eind");
  38. content.add(eind);
  39. final JLabel objectlabel = new JLabel("object");
  40. content.add(objectlabel);
  41. final JLabel letterx = new JLabel("x");
  42. content.add(letterx);
  43. final JLabel lettery = new JLabel("y");
  44. content.add(lettery);
  45. final JTextField x = new JTextField(20);
  46. content.add(x);
  47. final JTextField y = new JTextField(20);
  48. content.add(y);
  49. final JTextField bx = new JTextField(20);
  50. content.add(bx);
  51. final JTextField by = new JTextField(20);
  52. content.add(by);
  53. final JTextField ox = new JTextField(20);
  54. content.add(ox);
  55. final JTextField oy = new JTextField(20);
  56. content.add(oy);
  57. addButton.addActionListener(new ActionListener()
  58. {
  59. public void actionPerformed(ActionEvent event)
  60. {
  61. intx = Integer.parseInt(x.getText());
  62. inty = Integer.parseInt(y.getText());
  63. intbx = Integer.parseInt(bx.getText());
  64. intby = Integer.parseInt(by.getText());
  65. routeplanner.berekenRoute(intx, inty, intby, intbx, 0);
  66. }
  67. });
  68. startSimulatie.addActionListener(new ActionListener()
  69. {
  70. public void actionPerformed(ActionEvent event)
  71. {
  72. int teller = 0;
  73. intx = Integer.parseInt(x.getText());
  74. inty = Integer.parseInt(y.getText());
  75. intbx = Integer.parseInt(bx.getText());
  76. intby = Integer.parseInt(by.getText());
  77. String[] route = routeplanner.berekenRoute(intx, inty, intbx, intby, 0);
  78. int lengte = routeplanner.geefLengte();
  79. boolean botsing = boebotSimulator.voerOpdrachtUit(route, intbx, intby, lengte, intx, inty);
  80. while(botsing == true && teller < 3)
  81. {
  82. route = routeplanner.ontwijk(boebotSimulator.geefXX(), boebotSimulator.geefXY(), boebotSimulator.geefX(), boebotSimulator.geefY(), boebotSimulator.geefRotation());
  83. lengte = routeplanner.geefLengte();
  84. botsing = boebotSimulator.voerOpdrachtUit(route, boebotSimulator.geefX(), boebotSimulator.geefY(), lengte, intx, inty);
  85. route = routeplanner.berekenRoute(intx, inty, boebotSimulator.geefX(), boebotSimulator.geefY(), boebotSimulator.geefRotation());
  86. lengte = routeplanner.geefLengte();
  87. botsing = boebotSimulator.voerOpdrachtUit(route, boebotSimulator.geefX(), boebotSimulator.geefY(), lengte, intx, inty);
  88. teller ++;
  89. }
  90. if (teller == 3)
  91. {
  92. System.out.println("Boebot is de weg kwijt");
  93. }
  94. }
  95. });
  96. object.addActionListener(new ActionListener()
  97. {
  98. public void actionPerformed(ActionEvent event)
  99. {
  100. int intox = Integer.parseInt(ox.getText());
  101. int intoy = Integer.parseInt(oy.getText());
  102. System.out.println(boebotSimulator.plaatsObstakel(intox,intoy));
  103. }
  104. });
  105. popup.addActionListener(new ActionListener()
  106. {
  107. public void actionPerformed(ActionEvent event)
  108. {
  109. int locatie = (boebotSimulator.geefY() * 10) + 9 - boebotSimulator.geefX();
  110. boebotSimGUI = new BoebotSimGUI(boebotSimulator);
  111. }
  112. });
  113. begin.setBounds(20,0,200,20);
  114. eind.setBounds(150,0,200,20);
  115. addButton.setBounds(20,80,100,20);
  116. startSimulatie.setBounds(20,100,100,20);
  117. coordinaten.setBounds(20,60,200,20);
  118. object.setBounds(300,60,200,20);
  119. popup.setBounds(150,150,200,80);
  120. bx.setBounds(20,20,100,20);
  121. by.setBounds(20,40,100,20);
  122. letterx.setBounds(5,20,100,20);
  123. lettery.setBounds(5,40,100,20);
  124. ox.setBounds(300,20,100,20);
  125. oy.setBounds(300,40,100,20);
  126. x.setBounds(150,20,100,20);
  127. y.setBounds(150,40,100,20);
  128. setContentPane(content);
  129. setSize(700,300);
  130. setVisible(true);
  131. }
  132. }