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.java52
1 files changed, 31 insertions, 21 deletions
diff --git a/PunchingBag/src/PunchingBagGUI.java b/PunchingBag/src/PunchingBagGUI.java
index 60cacaa..5f1b571 100644
--- a/PunchingBag/src/PunchingBagGUI.java
+++ b/PunchingBag/src/PunchingBagGUI.java
@@ -22,8 +22,7 @@ import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
-public class PunchingBagGUI implements MouseListener, MouseMotionListener,
- ButtonListener, LEDListener {
+public class PunchingBagGUI implements MouseListener, MouseMotionListener, ButtonListener, LEDListener {
public static enum Mode {
Menu, Interactive, Game
@@ -70,11 +69,11 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
}
class LEDControlPanel extends JPanel implements ActionListener {
- String[] colours = {" ", "R", "Y", "G" };
+ String[] colours = { " ", "R", "Y", "G" };
public LEDControlPanel() {
this.setLayout(new GridBagLayout());
-
+
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.CENTER;
@@ -85,30 +84,44 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
for (int x = 0; x < bag.ledWidth; x++) {
c.gridx = x;
c.gridy = y;
-
+
RYGComboBoxRenderer renderer = new RYGComboBoxRenderer();
JComboBox rygCombo = new JComboBox(colours);
rygCombo.setSelectedIndex(0);
rygCombo.addActionListener(this);
rygCombo.setActionCommand(String.valueOf(x) + "," + String.valueOf(y));
- //rygCombo.setRenderer(renderer);
+ // rygCombo.setRenderer(renderer);
this.add(rygCombo, c);
}
}
+
+ c.gridx = 0;
+ c.gridy = 20;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.CENTER;
+ c.gridwidth = 9;
+ JButton clear = new JButton("Clear");
+ clear.setActionCommand("C");
+ clear.addActionListener(this);
+ this.add(clear, c);
}
public void actionPerformed(ActionEvent a) {
- PunchingBag.Colour colour = PunchingBag.Colour.None;
- if (((JComboBox)a.getSource()).getSelectedIndex() == 1) {
- colour = PunchingBag.Colour.Red;
- } else if (((JComboBox)a.getSource()).getSelectedIndex() == 2) {
- colour = PunchingBag.Colour.Yellow;
- } else if (((JComboBox)a.getSource()).getSelectedIndex() == 3) {
- colour = PunchingBag.Colour.Green;
+ if (a.getActionCommand() == "C") {
+ bag.clearLEDs();
+ } else {
+ PunchingBag.Colour colour = PunchingBag.Colour.None;
+ if (((JComboBox) a.getSource()).getSelectedIndex() == 1) {
+ colour = PunchingBag.Colour.Red;
+ } else if (((JComboBox) a.getSource()).getSelectedIndex() == 2) {
+ colour = PunchingBag.Colour.Yellow;
+ } else if (((JComboBox) a.getSource()).getSelectedIndex() == 3) {
+ colour = PunchingBag.Colour.Green;
+ }
+ System.out.println("Setting " + a.getActionCommand().split(",")[0] + " " + a.getActionCommand().split(",")[1]);
+ bag.setLED(Integer.valueOf(a.getActionCommand().split(",")[0]), Integer.valueOf(a.getActionCommand().split(",")[1]), colour);
}
- System.out.println("Setting " + a.getActionCommand().split(",")[0] + " " + a.getActionCommand().split(",")[1]);
- bag.setLED(Integer.valueOf(a.getActionCommand().split(",")[0]),Integer.valueOf( a.getActionCommand().split(",")[1]), colour);
}
class RYGComboBoxRenderer extends JLabel implements ListCellRenderer {
@@ -116,9 +129,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
super();
}
- public Component getListCellRendererComponent(JList list,
- Object value, int index, boolean isSelected,
- boolean cellHasFocus) {
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
// Get the selected index. (The index param isn't
// always valid, so just use the value.)
@@ -139,8 +150,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
}
}
- class PunchingBagSim extends JPanel implements ButtonListener, LEDListener,
- MouseListener {
+ class PunchingBagSim extends JPanel implements ButtonListener, LEDListener, MouseListener {
int buttonMinSize = 10;
int buttonMaxSize = 50;
@@ -249,7 +259,7 @@ public class PunchingBagGUI implements MouseListener, MouseMotionListener,
}
- class Button extends JPanel implements MouseListener {
+ class Button extends JComponent implements MouseListener {
final int x;
final int y;