|
@@ -2,6 +2,7 @@ import java.io.*;
|
|
|
import java.util.*;
|
|
|
import java.awt.*;
|
|
|
import javax.swing.*;
|
|
|
+import java.awt.event.*;
|
|
|
|
|
|
public class Sidepane extends JPanel implements Observer
|
|
|
{
|
|
@@ -16,7 +17,7 @@ public class Sidepane extends JPanel implements Observer
|
|
|
// changes.
|
|
|
this.model = model;
|
|
|
this.setPreferredSize(new Dimension(280, 720));
|
|
|
- colours = new Colours();
|
|
|
+ colours = new Colours(model);
|
|
|
this.add(colours);
|
|
|
model.addObserver(this);
|
|
|
}
|
|
@@ -34,20 +35,16 @@ public class Sidepane extends JPanel implements Observer
|
|
|
|
|
|
class Colours extends JPanel
|
|
|
{
|
|
|
- private JButton red;
|
|
|
- private JButton green;
|
|
|
- private JButton blue;
|
|
|
- private JButton yellow;
|
|
|
- private JButton purple;
|
|
|
- private JButton orange;
|
|
|
- private JButton cyan;
|
|
|
- private JButton custom;
|
|
|
+ private Model model;
|
|
|
private ArrayList<colourButton> colours;
|
|
|
|
|
|
- public Colours()
|
|
|
+ public Colours(Model m)
|
|
|
{
|
|
|
+ this.model = m;
|
|
|
this.setLayout(new GridLayout(0, 2));
|
|
|
this.setPreferredSize(new Dimension(280, 600));
|
|
|
+ this.colours = new ArrayList();
|
|
|
+ colourButton.model = m;
|
|
|
colours.add(new colourButton(Color.red));
|
|
|
colours.add(new colourButton(Color.green));
|
|
|
colours.add(new colourButton(Color.blue));
|
|
@@ -60,12 +57,21 @@ class Colours extends JPanel
|
|
|
for(colourButton b: colours)
|
|
|
{
|
|
|
this.add(b);
|
|
|
+ b.addActionListener(new ActionListener()
|
|
|
+ {
|
|
|
+ public void actionPerformed(ActionEvent e)
|
|
|
+ {
|
|
|
+ colourButton.model.changeColour(b.getBackground());
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
class colourButton extends JButton
|
|
|
{
|
|
|
+ public static Model model;
|
|
|
+
|
|
|
public colourButton(Color c)
|
|
|
{
|
|
|
this.setPreferredSize(new Dimension(140, 150));
|
|
@@ -77,4 +83,4 @@ class colourButton extends JButton
|
|
|
{
|
|
|
return this.getBackground().toString();
|
|
|
}
|
|
|
-}
|
|
|
+}
|