From f3804344d289e7f8008f3357c3907f2ecf333b91 Mon Sep 17 00:00:00 2001
From: Leon Dieter <Leon Dieter@DESKTOP-L4JC8N4>
Date: Thu, 18 Feb 2021 15:26:13 +0100
Subject: [PATCH] power_LED error eliminated / null pointer exception is
 missing

---
 .../letsgoing/ardublock/simulator/Simulator.java  |  1 +
 .../simulator/view/modules/ArduinoUno.java        | 15 ++++++++++++---
 .../ardublock/simulator/view/modules/Button.java  |  3 +--
 .../ardublock/simulator/view/modules/RGB.java     |  7 ++++++-
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/tec/letsgoing/ardublock/simulator/Simulator.java b/src/tec/letsgoing/ardublock/simulator/Simulator.java
index a34761b..ec6370a 100644
--- a/src/tec/letsgoing/ardublock/simulator/Simulator.java
+++ b/src/tec/letsgoing/ardublock/simulator/Simulator.java
@@ -135,6 +135,7 @@ public class Simulator implements Runnable, ActionListener{
 		arduino.getPin(20).setValue(1023); // Power ON LED
 		arduino.setStop(false);
 		arduino.getFunction("main").run(arduino, null);
+		
 	}
 
 	/**
diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java b/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java
index 84618c4..dd6f7b7 100644
--- a/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java
+++ b/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java
@@ -57,6 +57,14 @@ public class ArduinoUno extends Modul {
 	@Override
 	public void updateGUI(int _xscale, int _yscale) {
 		
+		//Alte label werden entfernt, wenn vorhanden. Da sonst die alten Label bestehen bleiben würden
+		if(labelPower != null) {
+			layerpane.remove(labelPower);
+		}
+		
+		if(label13 != null) {
+			layerpane.remove(label13);
+		}
 		
 		this.xscale = _xscale; 
 		this.yscale = _yscale;
@@ -72,12 +80,13 @@ public class ArduinoUno extends Modul {
 				chiplabel.setLocation(locx, locy);
 				layerpane.add(chiplabel, 0);
 
-				// Label für die PowerLED
+				// Label für die PowerLED
 				labelPower = new JLabel() {
 					private static final long serialVersionUID = 1L;
 
 					@Override
 					public void paintComponent(Graphics g) {
+						
 						Graphics2D ga = (Graphics2D) g;
 						int transparancy = 0;
 						if (ledOn)
@@ -87,7 +96,7 @@ public class ArduinoUno extends Modul {
 					}
 
 				};
-
+				
 				labelPower.setLocation(((int)(0.5207*xscale))+locx, ((int)(0.13*yscale))+locy);
 				labelPower.setSize(((int)(0.02066*xscale)), ((int)(0.01034*yscale)));
 				layerpane.add(labelPower, 0);
@@ -129,7 +138,7 @@ public class ArduinoUno extends Modul {
 		if (pin == pins.get(1)) {
 			led13 = pin.getValue();
 		}
-
+		
 	}
 
 	public boolean connect(Arduino _arduino) {
diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java
index fe09ebb..958dbea 100644
--- a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java
+++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java
@@ -140,8 +140,7 @@ public class Button extends Modul implements ActionListener {
 		
 		lastState[pin] = value;
 		pins.get(pin).setValue(value);
-		
-		System.out.println("called");
+	
 		
 	}
 
diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java
index ce82e74..3295014 100644
--- a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java
+++ b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java
@@ -48,6 +48,11 @@ public class RGB extends Modul {
 	public void updateGUI(int _xscale, int _yscale) {
 	
 	
+		//Alte label werden entfernt, wenn vorhanden. Da sonst die alten Label bestehen bleiben würden
+		if(ledlabel != null) {
+			layerpane.remove(ledlabel);
+		}
+		
 		this.xscale = _xscale; 
 		this.yscale = _yscale;
 		
@@ -57,7 +62,7 @@ public class RGB extends Modul {
 				chipIcon_temp = new ImageIcon(chipIcon.getImage().getScaledInstance(((int)(0.3037*xscale)), ((int)(0.304*yscale)), Image.SCALE_SMOOTH));
 				chiplabel.setIcon(chipIcon_temp);
 				chiplabel.setSize(((int)(0.3037*xscale)), ((int)(0.304*yscale)));
-				layerpane.add(chiplabel, 1);
+				layerpane.add(chiplabel, 0);
 
 				// Erzeuge ein JLabel welches das Leuchten der LED darstellt.
 				ledlabel = new JLabel() {
-- 
GitLab