Browse Source

adding sidepane and bottom control bar

tarfeef101 6 years ago
parent
commit
7c975055e9

+ 34 - 0
assignments/a2/src/main/java/Controls.java

@@ -0,0 +1,34 @@
+import java.io.*;
+import java.util.*;
+import java.awt.*;
+import javax.swing.*;
+
+public class Controls extends JPanel implements Observer
+{
+  private Model model;
+
+  // Bob the Builder this shit
+  public Controls(Model model)
+  {
+    // Hook up this observer so that it will be notified when the model
+    // changes.
+    this.model = model;
+    this.setPreferredSize(new Dimension(300, 30));
+    model.addObserver(this);
+  }
+  
+  public void updateColour()
+  {
+    this.setBackground(Color.PURPLE);
+    this.update(model);
+  }
+
+  /**
+  * Update with data from the model.
+  */
+  public void update(Object observable)
+  {
+    revalidate();
+    repaint();
+  }
+}

+ 4 - 0
assignments/a2/src/main/java/Main.java

@@ -9,6 +9,8 @@ public class Main
     Model model = new Model();
     View view = new View(model);
     Menubar menubar = new Menubar(model);
+    Sidepane sidepane = new Sidepane(model);
+    Controls controls = new Controls(model);
     model.notifyObservers();
     
     // create a layout panel to hold the views
@@ -17,6 +19,8 @@ public class Main
 		mainpanel.add(view, BorderLayout.CENTER);
 		mainpanel.add(menubar, BorderLayout.PAGE_START);
 		menubar.updateColour();
+		sidepane.updateColour();
+		controls.updateColour();
 		
 		// Setup the frame to do frame things
 		window.setPreferredSize(new Dimension(300,300));

+ 34 - 0
assignments/a2/src/main/java/Sidepane.java

@@ -0,0 +1,34 @@
+import java.io.*;
+import java.util.*;
+import java.awt.*;
+import javax.swing.*;
+
+public class Sidepane extends JPanel implements Observer
+{
+  private Model model;
+
+  // Bob the Builder this shit
+  public Sidepane(Model model)
+  {
+    // Hook up this observer so that it will be notified when the model
+    // changes.
+    this.model = model;
+    this.setPreferredSize(new Dimension(100, 300));
+    model.addObserver(this);
+  }
+  
+  public void updateColour()
+  {
+    this.setBackground(Color.GREEN);
+    this.update(model);
+  }
+
+  /**
+  * Update with data from the model.
+  */
+  public void update(Object observable)
+  {
+    revalidate();
+    repaint();
+  }
+}