Skip to content
Snippets Groups Projects
Commit 48a33260 authored by Leon Dieter's avatar Leon Dieter
Browse files

nullpointer exception problem/simulator problem when resized

parent bb9cde2f
No related branches found
No related tags found
No related merge requests found
...@@ -104,7 +104,7 @@ public class Simulator implements Runnable, ActionListener{ ...@@ -104,7 +104,7 @@ public class Simulator implements Runnable, ActionListener{
} }
/** /**
* Startet den Simulation<br> * Startet die Simulation<br>
* Wird durch den Play-Button gestartet. * Wird durch den Play-Button gestartet.
*/ */
public void startSimu() { public void startSimu() {
...@@ -179,6 +179,42 @@ public class Simulator implements Runnable, ActionListener{ ...@@ -179,6 +179,42 @@ public class Simulator implements Runnable, ActionListener{
for (SimCodeFunction function : functionsCode) { for (SimCodeFunction function : functionsCode) {
arduino.addFunction(function); arduino.addFunction(function);
} }
startSimu();
return true;
}
public boolean reloadGUI(GUI currentGUI) {
if (simuThread instanceof Thread) {
stopSimu();
try {
simuThread.join();
} catch (InterruptedException e) {
// e.printStackTrace();
arduino.errorAbort("Thread Überwachung gestört - Bitte Programm neustarten");
return false;
}
}
gui.stopThread();
this.gui = currentGUI;
arduino = new Arduino(gui);
gui.connectPins(arduino);
guiThread = new Thread(gui);
guiThread.start();
for (SimCodeFunction function : functionsCode) {
arduino.addFunction(function);
}
startSimu();
return true; return true;
} }
...@@ -196,6 +232,7 @@ public class Simulator implements Runnable, ActionListener{ ...@@ -196,6 +232,7 @@ public class Simulator implements Runnable, ActionListener{
} }
} }
startSimu(); startSimu();
//System.out.println("reset");
return true; return true;
} }
......
...@@ -53,8 +53,10 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -53,8 +53,10 @@ public class GUI extends JFrame implements Runnable, ActionListener {
private Modul[] modules = new Modul[4]; private Modul[] modules = new Modul[4];
private volatile boolean stopFlag = false; private volatile boolean stopFlag = false;
private JTextArea serialLog = new JTextArea(); private JTextArea serialLog = new JTextArea();
private static int xscale= 720; private static int xscale= 1500;
private static int yscale= 720; private static int yscale= 1000;
private JPanel modulPanel;
private Container mainPane;
/** /**
* Konstruktor der Klasse GUI * Konstruktor der Klasse GUI
...@@ -63,14 +65,29 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -63,14 +65,29 @@ public class GUI extends JFrame implements Runnable, ActionListener {
*/ */
public GUI(Simulator simu) { public GUI(Simulator simu) {
super("ArduBlock Simulator"); super("ArduBlock Simulator");
createGUI(simu);
this.addComponentListener(new ComponentListener() { this.addComponentListener(new ComponentListener() {
@Override @Override
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
if(!(xscale == getWidth() && yscale == getHeight())) {
if(modulPanel.getWidth() <= modulPanel.getHeight()) {
xscale = getWidth(); xscale = getWidth();
yscale = getHeight(); yscale = getHeight();
}
else {
xscale = getWidth();
yscale = getHeight();
}
updating(simu);
System.out.println("xScale: " + xscale + "\tyScale: " + yscale); System.out.println("xScale: " + xscale + "\tyScale: " + yscale);
} }
}
@Override @Override
public void componentMoved(ComponentEvent e) { public void componentMoved(ComponentEvent e) {
...@@ -92,6 +109,23 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -92,6 +109,23 @@ public class GUI extends JFrame implements Runnable, ActionListener {
}); });
}
public void updating(Simulator simu) {
mainPane.removeAll();
createGUI(simu);
//simu.reloadGUI(this);
}
public void createGUI(Simulator simu) {
// Konstruktor der Module // Konstruktor der Module
modules[0] = new RGB(new ImageIcon(getToolkit() modules[0] = new RGB(new ImageIcon(getToolkit()
.getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM31_RGB_LED.png")))); .getImage(GUI.class.getResource("/tec/letsgoing/ardublock/simulator/img/PM31_RGB_LED.png"))));
...@@ -114,10 +148,10 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -114,10 +148,10 @@ public class GUI extends JFrame implements Runnable, ActionListener {
this.setResizable(true); //TODO Muss in true ge�ndert werden wenn skalierbar this.setResizable(true); //TODO Muss in true ge�ndert werden wenn skalierbar
Container mainPane = this.getContentPane(); mainPane = this.getContentPane();
// Panel welches alle Module sowie die Verdrahtung enth�lt. // Panel welches alle Module sowie die Verdrahtung enth�lt.
JPanel modulPanel = new JPanel(new BorderLayout()) { modulPanel = new JPanel(new BorderLayout()) {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
...@@ -137,12 +171,12 @@ public class GUI extends JFrame implements Runnable, ActionListener { ...@@ -137,12 +171,12 @@ public class GUI extends JFrame implements Runnable, ActionListener {
//Panel der Buttons auf der rechten Seite wird ausgeblendet //Panel der Buttons auf der rechten Seite wird ausgeblendet
//mainPane.add(createControlPanel(simu), BorderLayout.LINE_END); //mainPane.add(createControlPanel(simu), BorderLayout.LINE_END);
mainPane.add(createSerialLog(), BorderLayout.PAGE_END); mainPane.add(createSerialLog(), BorderLayout.PAGE_END);
this.pack(); this.setSize(xscale, yscale);
// this.setLocation(-1300, 0); //M�glichkeit die Renderingposition festzulegen //this.pack();
// this.setLocation(-1300, 0); //Mglichkeit die Renderingposition festzulegen
this.setVisible(true); this.setVisible(true);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment