瀏覽代碼

trying out a menubar. prev version did compile/create a window

tarfeef101 6 年之前
父節點
當前提交
82751e1e6f

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

@@ -8,12 +8,14 @@ public class Main
     JFrame window = new JFrame("Paint, but worse");
     Model model = new Model();
     View view = new View(model);
+    Menubar menubar = new Menubar(model);
     model.notifyObservers();
     
     // create a layout panel to hold the views
 		JPanel mainpanel = new JPanel(new BorderLayout(10, 10));
 		window.getContentPane().add(mainpanel);
 		mainpanel.add(view, BorderLayout.CENTER);
+		mainpanel.add(menubar, BorderLayout.PAGE_START);
 		
 		// Setup the frame to do frame things
 		window.setPreferredSize(new Dimension(300,300));

+ 33 - 0
assignments/a2/src/main/java/Menubar.java

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

+ 0 - 1
assignments/a2/src/main/java/View.java

@@ -21,7 +21,6 @@ public class View extends JPanel implements Observer
   */
   public void update(Object observable)
   {
-    System.out.println("Model changed!");
     revalidate();
     repaint();
   }