aboutsummaryrefslogtreecommitdiff
path: root/PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java
diff options
context:
space:
mode:
Diffstat (limited to 'PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java')
-rw-r--r--PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java b/PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java
index a8d32ff..b2d96a5 100644
--- a/PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java
+++ b/PunchingBag/src/uk/ac/open/punchingbag/examples/SimpleKeyboard.java
@@ -1,6 +1,7 @@
package uk.ac.open.punchingbag.examples;
import java.awt.Color;
+import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
@@ -15,7 +16,7 @@ import uk.ac.open.punchingbag.ButtonListener;
import uk.ac.open.punchingbag.Contact;
import uk.ac.open.punchingbag.PunchingBag;
-public class SimpleKeyboard implements ButtonListener {
+public class SimpleKeyboard implements ButtonListener, Runnable {
String soundDir = System.getProperty("user.dir")
+ System.getProperty("file.separator");
@@ -26,6 +27,7 @@ public class SimpleKeyboard implements ButtonListener {
new File(soundDir + "G5.wav") };
static PunchingBag bag = PunchingBag.getBag();
+ long lastActionTime = System.currentTimeMillis();
public static void main(String[] args) {
new SimpleKeyboard();
@@ -39,9 +41,11 @@ public class SimpleKeyboard implements ButtonListener {
// TODO Auto-generated catch block
e.printStackTrace();
}
+ new Thread (this).start();
}
public void buttonPressed(int x, int y) {
+ lastActionTime = System.currentTimeMillis();
System.out.println("Button Pressed: " + x + " " + y);
if (y < 3) {
bag.fillRect(0, 0, 9, 4, Color.red, 500);
@@ -90,5 +94,15 @@ public class SimpleKeyboard implements ButtonListener {
}
+ @Override
+ public void run() {
+ while (true) {
+ if ((System.currentTimeMillis() - lastActionTime) > 4000) {
+ bag.noise(new Rectangle(0, 0, 9, 20));
+ }
+ }
+
+ }
+
}