aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2011-08-24 22:39:49 +0100
committerChristopher Baines <cbaines8@gmail.com>2011-08-24 22:39:49 +0100
commit4667303e15c534d390abee467eeaaee850e2d6f5 (patch)
treeae4f8e2df6b455bd235dc9b7547a62da17a59008
parentd01fc7da9367c0d5032741a9189258b467ce5eef (diff)
downloadpunchingbag-4667303e15c534d390abee467eeaaee850e2d6f5.tar
punchingbag-4667303e15c534d390abee467eeaaee850e2d6f5.tar.gz
New API for bag.
-rw-r--r--PunchingBag/bin/ButtonListener.classbin0 -> 173 bytes
-rw-r--r--PunchingBag/bin/Contact.classbin0 -> 444 bytes
-rw-r--r--PunchingBag/bin/PunchingBag.classbin0 -> 755 bytes
-rw-r--r--PunchingBag/bin/PunchingBagGUI$Area.classbin595 -> 0 bytes
-rw-r--r--PunchingBag/bin/PunchingBagGUI$Contact.classbin974 -> 0 bytes
-rw-r--r--PunchingBag/bin/PunchingBagGUI$Direction.classbin1191 -> 1191 bytes
-rw-r--r--PunchingBag/bin/PunchingBagGUI$Mode.classbin1070 -> 1070 bytes
-rw-r--r--PunchingBag/bin/PunchingBagGUI$Ripple.classbin1943 -> 1614 bytes
-rw-r--r--PunchingBag/bin/PunchingBagGUI.classbin3842 -> 3613 bytes
-rw-r--r--PunchingBag/src/ButtonListener.java7
-rw-r--r--PunchingBag/src/Contact.java19
-rw-r--r--PunchingBag/src/PunchingBag.java24
-rw-r--r--PunchingBag/src/PunchingBagGUI.java73
13 files changed, 69 insertions, 54 deletions
diff --git a/PunchingBag/bin/ButtonListener.class b/PunchingBag/bin/ButtonListener.class
new file mode 100644
index 0000000..acd177b
--- /dev/null
+++ b/PunchingBag/bin/ButtonListener.class
Binary files differ
diff --git a/PunchingBag/bin/Contact.class b/PunchingBag/bin/Contact.class
new file mode 100644
index 0000000..2e6fbc5
--- /dev/null
+++ b/PunchingBag/bin/Contact.class
Binary files differ
diff --git a/PunchingBag/bin/PunchingBag.class b/PunchingBag/bin/PunchingBag.class
new file mode 100644
index 0000000..65f48c7
--- /dev/null
+++ b/PunchingBag/bin/PunchingBag.class
Binary files differ
diff --git a/PunchingBag/bin/PunchingBagGUI$Area.class b/PunchingBag/bin/PunchingBagGUI$Area.class
deleted file mode 100644
index 49b8d90..0000000
--- a/PunchingBag/bin/PunchingBagGUI$Area.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/PunchingBagGUI$Contact.class b/PunchingBag/bin/PunchingBagGUI$Contact.class
deleted file mode 100644
index 54a4389..0000000
--- a/PunchingBag/bin/PunchingBagGUI$Contact.class
+++ /dev/null
Binary files differ
diff --git a/PunchingBag/bin/PunchingBagGUI$Direction.class b/PunchingBag/bin/PunchingBagGUI$Direction.class
index acb7f1a..654a7b0 100644
--- a/PunchingBag/bin/PunchingBagGUI$Direction.class
+++ b/PunchingBag/bin/PunchingBagGUI$Direction.class
Binary files differ
diff --git a/PunchingBag/bin/PunchingBagGUI$Mode.class b/PunchingBag/bin/PunchingBagGUI$Mode.class
index 27359c3..1b33757 100644
--- a/PunchingBag/bin/PunchingBagGUI$Mode.class
+++ b/PunchingBag/bin/PunchingBagGUI$Mode.class
Binary files differ
diff --git a/PunchingBag/bin/PunchingBagGUI$Ripple.class b/PunchingBag/bin/PunchingBagGUI$Ripple.class
index 4a7e871..b824480 100644
--- a/PunchingBag/bin/PunchingBagGUI$Ripple.class
+++ b/PunchingBag/bin/PunchingBagGUI$Ripple.class
Binary files differ
diff --git a/PunchingBag/bin/PunchingBagGUI.class b/PunchingBag/bin/PunchingBagGUI.class
index 424f5bc..362e5e7 100644
--- a/PunchingBag/bin/PunchingBagGUI.class
+++ b/PunchingBag/bin/PunchingBagGUI.class
Binary files differ
diff --git a/PunchingBag/src/ButtonListener.java b/PunchingBag/src/ButtonListener.java
new file mode 100644
index 0000000..9514da6
--- /dev/null
+++ b/PunchingBag/src/ButtonListener.java
@@ -0,0 +1,7 @@
+import java.util.EventListener;
+
+interface ButtonListener extends EventListener {
+
+ void contact(Contact c);
+
+}
diff --git a/PunchingBag/src/Contact.java b/PunchingBag/src/Contact.java
new file mode 100644
index 0000000..8e8970b
--- /dev/null
+++ b/PunchingBag/src/Contact.java
@@ -0,0 +1,19 @@
+
+
+ class Contact {
+ // Height of bag is
+
+ final long time; // Time of the contact with the bag (in millis)
+ final int x;
+ final int y;
+ final int strength; // 0 - 100
+
+ Contact(long time, int x, int y, int strength) {
+ this.time = time;
+ this.x = x;
+ this.y = y;
+ this.strength = strength;
+ }
+
+
+ } \ No newline at end of file
diff --git a/PunchingBag/src/PunchingBag.java b/PunchingBag/src/PunchingBag.java
new file mode 100644
index 0000000..278a8fc
--- /dev/null
+++ b/PunchingBag/src/PunchingBag.java
@@ -0,0 +1,24 @@
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.event.EventListenerList;
+
+
+public class PunchingBag {
+ protected EventListenerList listenerList = new EventListenerList();
+
+ /**
+ * Adds an <code>ActionListener</code> to the button.
+ * @param l the <code>ActionListener</code> to be added
+ */
+ public void addButtonListener(ButtonListener l) {
+ listenerList.add(ButtonListener.class, l);
+ }
+
+ public void setLED(byte x, byte y, byte intensity) {
+
+
+ }
+
+}
diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java
index 8008c58..1bd1415 100644
--- a/PunchingBag/src/PunchingBagGUI.java
+++ b/PunchingBag/src/PunchingBagGUI.java
@@ -1,14 +1,16 @@
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 {
+public class PunchingBagGUI implements MouseListener, MouseMotionListener, ButtonListener {
public static enum Mode {
Menu, Interactive, Game
@@ -21,6 +23,8 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener {
static JFrame frame;
static JFrame bagSimFrame;
+
+ static PunchingBag bag = new PunchingBag();
// Contact
public enum Direction {
@@ -30,9 +34,10 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener {
final boolean useDebugScreen = true;
public static void main(String[] args) throws InterruptedException {
- SlaveArduino.listPorts();
+ //SlaveArduino.listPorts();
+
+ new PunchingBagGUI();
- //new PunchingBagGUI();
}
PunchingBagGUI() throws InterruptedException {
@@ -51,6 +56,8 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener {
System.out.println("Bag X: " + bagSimFrame.getX() + " Bag Y: "
+ bagSimFrame.getY());
+
+ bag.addButtonListener(this);
draw();
}
@@ -68,19 +75,11 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener {
class Ripple extends JPanel {
final Contact contact;
- final int width;
double currentWidth;
Ripple(Contact contact) {
super();
this.contact = contact;
- if (contact.area.width >= contact.area.height) {
- width = contact.area.width;
- } else {
- width = contact.area.height;
- }
- currentWidth = width;
- if (currentWidth <= 0.5) currentWidth = 0.5;
}
public void paintComponent(Graphics g) {
@@ -88,13 +87,13 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener {
// Ripple will expand 60cm * strength/100
SlaveArduino.Colour colour = SlaveArduino.Colour.Red;
- g.setColor(new Color(255, 0, 0, 255 - width));
+ g.setColor(new Color(255, 0, 0, 255));
boolean drawnSomething = false;
for (double i = 0; i < 360; i++) {
- int x = contact.area.x
+ int x = contact.x
+ (int) Math.round(currentWidth * Math.cos(i));
- int y = contact.area.y
+ int y = contact.y
+ (int) Math.round(currentWidth * Math.sin(i));
if (x >= 0 && x <= 8 && y >= 0 && y <= 19) {
@@ -113,41 +112,6 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener {
}
}
- class Contact {
- // Height of bag is
-
- final long time; // Time of the contact with the bag (in millis)
- final Area area;
- final Direction direction;
- final int strength; // 0 - 100
-
- Contact(long time, Area area, Direction direction, int strength) {
- this.time = time;
- this.area = area;
- this.direction = direction;
- this.strength = strength;
- }
-
- Contact(long time, Area area) {
- this(time, area, Direction.None, 50);
- }
-
- }
-
- class Area {
- public final int x;
- public final int y;
- public final int width;
- public final int height;
-
- Area(int x, int y, int width, int height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
-
- }
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
@@ -165,13 +129,9 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener {
}
public void mousePressed(MouseEvent arg0) {
- System.out.println("Mouse moved");
if (currentMode == Mode.Interactive) {
- System.out.println("Button: " + arg0.getButton());
- runInteractively(new Contact(System.currentTimeMillis(), new Area(
- (arg0.getX() - 4) / 40, (arg0.getY() - 30) / 40, 0, 0), Direction.None , 30 * arg0.getButton()));
+ runInteractively(new Contact(System.currentTimeMillis(), (arg0.getX() - 4)/ 40 , (arg0.getY() - 30) / 40, 0));
}
- Toolkit.getDefaultToolkit().beep();
}
public void mouseReleased(MouseEvent arg0) {
@@ -189,4 +149,9 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener {
}
+ public void contact(Contact c) {
+ // TODO Auto-generated method stub
+
+ }
+
}