diff options
-rw-r--r-- | PunchingBag/src/PunchingBag.java | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java index 0bcd5c7..00a5866 100644 --- a/PunchingBag/src/PunchingBag.java +++ b/PunchingBag/src/PunchingBag.java @@ -7,7 +7,7 @@ import java.util.Iterator; // TODO: Loads of threads in this class, make sure everything is thread safe. public class PunchingBag implements Runnable { - + boolean ledsChanged = false; final public int ledHeight = 20; final public int ledWidth = 9; private byte[] rawLeds = new byte[6 * 8]; @@ -21,6 +21,7 @@ public class PunchingBag implements Runnable { None, Red, Yellow, Green }; + // Is there a better class for this? One that it is not a swing class. private EventListenerList buttonListenerList = new EventListenerList(); private EventListenerList ledListenerList = new EventListenerList(); @@ -44,7 +45,11 @@ public class PunchingBag implements Runnable { public boolean setLED(int x, int y, Colour colour) { if (x >= 0 && x < ledWidth && y >= 0 && y < ledHeight) { - leds[x][y] = colour; + if (leds[x][y] != colour) { + leds[x][y] = colour; + ledsChanged = true; + + } return true; } else { return false; @@ -107,9 +112,11 @@ public class PunchingBag implements Runnable { } currentRadius += 0.1 + (currentRadius / 10); - // longhand: currentRadius = currentRadius + 0.1 + (currentRadius / 10); + // longhand: currentRadius = currentRadius + 0.1 + (currentRadius / + // 10); - if (!DrawEllipse(2, 4, (int) currentRadius, (int) currentRadius, colour)) + if (!DrawEllipse(2, 4, (int) currentRadius, (int) currentRadius, + colour)) stop = true; } @@ -213,7 +220,17 @@ public class PunchingBag implements Runnable { } public void run() { + while (true) { + if (ledsChanged) { + //LEDListeners = + //ledListenerList. + } + try { + Thread.sleep(1000 / 120); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } - } |