From a06191781dd330372cab86acc02cfbb81e4c5624 Mon Sep 17 00:00:00 2001 From: Leon Dieter <Leon Dieter@DESKTOP-L4JC8N4> Date: Wed, 17 Feb 2021 20:45:09 +0100 Subject: [PATCH] LED label is flashing / nullpointerexception error left --- .../ardublock/simulator/view/GUI.java | 5 +---- .../simulator/view/modules/ArduinoUno.java | 5 ++++- .../simulator/view/modules/Button.java | 4 +++- .../simulator/view/modules/Poti.java | 10 ++++++--- .../ardublock/simulator/view/modules/RGB.java | 22 +++++++++++++------ 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/tec/letsgoing/ardublock/simulator/view/GUI.java b/src/tec/letsgoing/ardublock/simulator/view/GUI.java index cb2516d..6bfcc43 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/GUI.java +++ b/src/tec/letsgoing/ardublock/simulator/view/GUI.java @@ -169,10 +169,7 @@ public class GUI extends JFrame implements Runnable, ActionListener { modules[2].updateGUI(xscale, yscale); modules[3].updateGUI(xscale, yscale); - - - - + } diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java b/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java index ab6352d..84618c4 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/ArduinoUno.java @@ -55,8 +55,11 @@ public class ArduinoUno extends Modul { } @Override - public void updateGUI(int xscale, int yscale) { + public void updateGUI(int _xscale, int _yscale) { + + this.xscale = _xscale; + this.yscale = _yscale; // Offset für den Arduino um diesen mehr mittig zu platzieren. int locx = ((int)(0.0516*xscale)); int locy = ((int)(0.0517*yscale)); diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java index 05f4c5d..fe09ebb 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Button.java @@ -44,7 +44,7 @@ public class Button extends Modul implements ActionListener { label2 = new JLabel(); label3 = new JLabel(); updateGUI(xscale, yscale); - calculatePinPos(); + } public void updateGUI(int _xscale, int _yscale){ @@ -91,6 +91,8 @@ public class Button extends Modul implements ActionListener { layerpane.add(label1, 0); layerpane.add(label2, 0); layerpane.add(label3, 0); + + calculatePinPos(); } public void updateModul(Pin pin) { diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java b/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java index 6e829fc..1eeea9a 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/Poti.java @@ -64,12 +64,16 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener { updateGUI(xscale, yscale); - calculatePinPos(); + } @Override - public void updateGUI(int xscale, int yscale) { + public void updateGUI(int _xscale, int _yscale) { + + + this.xscale = _xscale; + this.yscale = _yscale; layerpane.setPreferredSize(new Dimension(((int)(0.3037*xscale)), ((int)(0.304*yscale)))); @@ -81,7 +85,7 @@ public class Poti extends Modul implements ChangeListener, MouseWheelListener { sliderPanel.setSize(((int)(0.2066*xscale)), ((int)(0.0517*yscale))); sliderPanel.setLocation(((int)(0.04855*xscale)), ((int)(0.175*yscale))); - + calculatePinPos(); } public void updateModul(Pin arg0) { diff --git a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java index 3f3d646..ce82e74 100644 --- a/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java +++ b/src/tec/letsgoing/ardublock/simulator/view/modules/RGB.java @@ -28,6 +28,7 @@ public class RGB extends Modul { private int redValue = 0; private int greenValue = 0; private int blueValue = 0; + private int transparancy, tredValue, tgreenValue, tblueValue; private JLabel chiplabel, ledlabel; private ImageIcon chipIcon, chipIcon_temp; private int xscale = GUI.getxscale(); @@ -40,12 +41,15 @@ public class RGB extends Modul { chipIcon = _icon; updateGUI(xscale, yscale); - calculatePinPos(); + } @Override - public void updateGUI(int xscale, int yscale) { + public void updateGUI(int _xscale, int _yscale) { + + this.xscale = _xscale; + this.yscale = _yscale; // Erstellen der JLayerPane für das Modul layerpane.setPreferredSize(new Dimension(((int)(0.3037*xscale)), ((int)(0.304*yscale)))); @@ -62,8 +66,10 @@ public class RGB extends Modul { @Override public void paintComponent(Graphics g) { Graphics2D ga = (Graphics2D) g; - int transparancy = (int) (Math.max(redValue, Math.max(greenValue, blueValue)) * 0.9); - int tredValue = 0, tgreenValue = 0, tblueValue = 0; + transparancy = (int) (Math.max(redValue, Math.max(greenValue, blueValue)) * 0.9); + tredValue = 0; + tgreenValue = 0; + tblueValue = 0; if (transparancy != 0) { if (redValue > 0) tredValue = map(redValue); @@ -72,10 +78,12 @@ public class RGB extends Modul { if (blueValue > 0) tblueValue = map(blueValue); } - // System.out.println(tredValue+" "+ tgreenValue+" "+ tblueValue+" "+ - // transparancy); + //System.out.println(tredValue+" "+ tgreenValue+" "+ tblueValue+" "+ + //transparancy); + ga.setPaint(new Color(tredValue, tgreenValue, tblueValue, transparancy)); ga.fillOval(0, 0, ((int)(0.07541*xscale)), ((int)(0.07549*yscale))); + //System.out.println("blink"); } }; @@ -85,7 +93,7 @@ public class RGB extends Modul { ledlabel.setSize(((int)(0.2066*xscale)), ((int)(0.2068*yscale))); layerpane.add(ledlabel, 0); - + calculatePinPos(); } /** -- GitLab