Quellcode durchsuchen

i can see clearly now, the lines are drawn

tsdedhar vor 6 Jahren
Ursprung
Commit
e24d6370cc

BIN
assignments/a2/.gradle/4.7/fileHashes/fileHashes.bin


BIN
assignments/a2/.gradle/4.7/fileHashes/fileHashes.lock


BIN
assignments/a2/.gradle/4.7/taskHistory/taskHistory.bin


BIN
assignments/a2/.gradle/4.7/taskHistory/taskHistory.lock


BIN
assignments/a2/.gradle/buildOutputCleanup/buildOutputCleanup.lock


BIN
assignments/a2/build/classes/java/main/Model.class


BIN
assignments/a2/build/classes/java/main/Thingy.class


BIN
assignments/a2/build/classes/java/main/View.class


BIN
assignments/a2/build/libs/a2-1.0-SNAPSHOT.jar


+ 11 - 5
assignments/a2/src/main/java/Model.java

@@ -28,11 +28,15 @@ public class Model extends Observable
     curThingy = new Thingy(curColour, curThiccness);
     curThingy = new Thingy(curColour, curThiccness);
     thingies.add(curThingy);
     thingies.add(curThingy);
     curThingy.addPoint(x, y);
     curThingy.addPoint(x, y);
+    setChanged();
+    notifyObservers();
   }
   }
   
   
   public void addPoint(int x, int y)
   public void addPoint(int x, int y)
   {
   {
     curThingy.addPoint(x, y);
     curThingy.addPoint(x, y);
+    setChanged();
+    notifyObservers();
   }
   }
   
   
   public ArrayList<Thingy> getThingies()
   public ArrayList<Thingy> getThingies()
@@ -44,21 +48,21 @@ public class Model extends Observable
   {
   {
     menuColour = c;
     menuColour = c;
     setChanged();
     setChanged();
-		notifyObservers();
+    notifyObservers();
   }
   }
   
   
   public void setSideColour(Color c)
   public void setSideColour(Color c)
   {
   {
     sideColour = c;
     sideColour = c;
     setChanged();
     setChanged();
-		notifyObservers();
+    notifyObservers();
   }
   }
   
   
   public void setControlColour(Color c)
   public void setControlColour(Color c)
   {
   {
     controlColour = c;
     controlColour = c;
     setChanged();
     setChanged();
-		notifyObservers();
+    notifyObservers();
   }
   }
 
 
   // Add observer to be notified on change
   // Add observer to be notified on change
@@ -92,8 +96,10 @@ class Thingy
   public Thingy(Color c, int x)
   public Thingy(Color c, int x)
   {
   {
     points = new ArrayList();
     points = new ArrayList();
-    this.colour = c;
-    this.thiccness = x;
+    //this.colour = c;
+    this.colour = Color.black;
+    //this.thiccness = x;
+    this.thiccness = 5;
   }
   }
   
   
   public void addPoint(int x, int y)
   public void addPoint(int x, int y)

+ 6 - 5
assignments/a2/src/main/java/View.java

@@ -1,4 +1,3 @@
-import java.io.*;
 import java.util.*;
 import java.util.*;
 import java.awt.*;
 import java.awt.*;
 import javax.swing.*;
 import javax.swing.*;
@@ -13,6 +12,7 @@ public class View extends JPanel implements Observer
     // Hook up this observer so that it will be notified when the model
     // Hook up this observer so that it will be notified when the model
     // changes.
     // changes.
     this.model = model;
     this.model = model;
+    this.setBackground(Color.white);
     model.addObserver(this);
     model.addObserver(this);
     this.addMouseMotionListener(handler);
     this.addMouseMotionListener(handler);
     this.addMouseListener(handler);
     this.addMouseListener(handler);
@@ -29,14 +29,15 @@ public class View extends JPanel implements Observer
   
   
   public void paintComponent(Graphics g)
   public void paintComponent(Graphics g)
   {
   {
-    Graphics gtemp = (Graphics2D) g;
-    ArrayList<Thingy> thingies = m.getThingies();
+    super.paintComponent(g);
+    Graphics2D gtemp = (Graphics2D) g;
+    ArrayList<Thingy> thingies = model.getThingies();
     
     
     for (Thingy t: thingies)
     for (Thingy t: thingies)
     {
     {
       ArrayList<Point> points = t.getPoints();
       ArrayList<Point> points = t.getPoints();
-      gtemp.setColor(points.get(0).getColour());
-      gtemp.setStroke(new BasicStroke(p.getThiccness(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+      gtemp.setColor(t.getColour());
+      gtemp.setStroke(new BasicStroke(t.getThiccness(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); 
       
       
       if ((points.size() ==  1))
       if ((points.size() ==  1))
       {
       {