From 8721d9014c86909910fbc9031e0c9e7668e49826 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Sep 2011 12:08:24 +0100 Subject: Added idle noise --- .../src/uk/ac/open/punchingbag/PunchingBagGUI.java | 6 +++--- .../uk/ac/open/punchingbag/examples/SimpleKeyboard.java | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java b/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java index 4acb2d0..e03c4e6 100644 --- a/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java +++ b/PunchingBag/src/uk/ac/open/punchingbag/PunchingBagGUI.java @@ -64,7 +64,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, Debug, Menu }; - Mode currentMode = Mode.Menu; + Mode currentMode = Mode.Debug; JFrame frame; @@ -146,8 +146,8 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener, programOptionsPanel.add(new JButton("Debug")); frame.add(bagDebugingPanel); - frame.add(new DisplayPanel(), BorderLayout.CENTER); - frame.add(programOptionsPanel, BorderLayout.SOUTH); + //frame.add(new DisplayPanel(), BorderLayout.CENTER); + //frame.add(programOptionsPanel, BorderLayout.SOUTH); setMode(currentMode); 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)); + } + } + + } + } -- cgit v1.2.3