aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag/src/PunchingBagGUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'PunchingBag/src/PunchingBagGUI.java')
-rw-r--r--PunchingBag/src/PunchingBagGUI.java56
1 files changed, 36 insertions, 20 deletions
diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java
index a999bad..f3997a8 100644
--- a/PunchingBag/src/PunchingBagGUI.java
+++ b/PunchingBag/src/PunchingBagGUI.java
@@ -1,16 +1,13 @@
import java.awt.Color;
import java.awt.Graphics;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
-import java.awt.geom.Area;
import javax.swing.JFrame;
-import javax.swing.JPanel;
-public class PunchingBagGUI implements MouseListener, MouseMotionListener, ButtonListener, LEDListener {
+public class PunchingBagGUI implements MouseListener, MouseMotionListener,
+ ButtonListener, LEDListener {
public static enum Mode {
Menu, Interactive, Game
@@ -23,7 +20,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, Butto
static JFrame frame;
static JFrame bagSimFrame;
-
+
static PunchingBag bag = new PunchingBag();
// Contact
@@ -34,10 +31,10 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, Butto
final boolean useDebugScreen = true;
public static void main(String[] args) throws InterruptedException {
- //SlaveArduino.listPorts();
-
+ // SlaveArduino.listPorts();
+
new PunchingBagGUI();
-
+
}
PunchingBagGUI() throws InterruptedException {
@@ -56,25 +53,25 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, Butto
System.out.println("Bag X: " + bagSimFrame.getX() + " Bag Y: "
+ bagSimFrame.getY());
-
+
bag.addButtonListener(this);
bag.addLEDChangeListener(this);
-
+
draw();
}
void draw() throws InterruptedException {
bagSimFrame.paintComponents(bagSimFrame.getGraphics());
// bagSimFrame.paintAll(bagSimFrame.getGraphics());
- Thread.sleep(16);
+ Thread.sleep(50);
draw();
}
public void runInteractively(Contact contact) {
-
+ System.out.println("Contact");
+ bag.buttonPressed(contact.x, contact.y);
}
-
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
@@ -92,7 +89,8 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, Butto
public void mousePressed(MouseEvent arg0) {
if (currentMode == Mode.Interactive) {
- runInteractively(new Contact(System.currentTimeMillis(), (arg0.getX() - 4)/ 40 , (arg0.getY() - 30) / 40, 0));
+ runInteractively(new Contact(System.currentTimeMillis(), (arg0
+ .getX() - 4) / 40, (arg0.getY() - 30) / 40, 0));
}
}
@@ -113,19 +111,37 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, Butto
public void contact(Contact c) {
// TODO Auto-generated method stub
-
+
}
@Override
public void buttonPressed(int x, int y) {
- // TODO Auto-generated method stub
-
+ System.out.println("Button Pressed: " + x + " " + y);
+ bag.CircleExpand(x, y, 16);
+
}
@Override
public void LEDchanged() {
- // TODO Auto-generated method stub
-
+ for (int x = 0; x < bag.ledWidth; x++) {
+ for (int y = 0; y < bag.ledHeight; y++) {
+ if (useDebugScreen) {
+ Graphics g = bagSimFrame.getGraphics();
+ if (bag.getLED(x, y) == PunchingBag.Colour.Red) {
+ g.setColor(Color.red);
+ g.fillOval(40 * x, 40 * y, 6, 6);
+ } else if (bag.getLED(x, y) == PunchingBag.Colour.Green) {
+ g.setColor(Color.green);
+ g.fillOval(40 * x, 40 * y, 6, 6);
+ }
+ if (bag.getLED(x, y) == PunchingBag.Colour.Yellow) {
+ g.setColor(Color.yellow);
+ g.fillOval(40 * x, 40 * y, 6, 6);
+ }
+ }
+ }
+ }
+
}
}