Przeglądaj źródła

fixing update of slider position

tarfeef101 6 lat temu
rodzic
commit
37de739142

+ 1 - 1
assignments/a2/src/main/java/Controls.java

@@ -42,7 +42,7 @@ public class Controls extends JPanel implements Observer
       playback.toggleSettingLen();
       playback.setMaximum(len);
       playback.toggleSettingLen();
-      //playback.setValue(len);
+      playback.setValue(model.getTotalVisibleLen());
     }
     this.setBackground(model.controlColour);
     revalidate();

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

@@ -13,6 +13,7 @@ public class Model extends Observable
   private Color curColour;
   private int curThiccness;
   private int totalLen;
+  private int totalVisibleLen;
   public Color sideColour;
   public Color controlColour;
 
@@ -24,6 +25,7 @@ public class Model extends Observable
     this.curColour = Color.black;
     this.curThiccness = 5;
     this.totalLen = 0;
+    this.totalVisibleLen = 0;
     setChanged();
   }
   
@@ -33,6 +35,7 @@ public class Model extends Observable
     thingies.add(curThingy);
     curThingy.addPoint(x, y);
     totalLen++;
+    totalVisibleLen++:
     setChanged();
     notifyObservers();
   }
@@ -41,6 +44,7 @@ public class Model extends Observable
   {
     curThingy.addPoint(x, y);
     totalLen++;
+    totalVisibleLen++;
     setChanged();
     notifyObservers();
   }
@@ -50,6 +54,11 @@ public class Model extends Observable
     return totalLen;
   }
   
+  public int getTotalVisibleLen()
+  {
+    return totalVisibleLen;
+  }
+  
   public ArrayList<Thingy> getThingies()
   {
     return thingies;
@@ -76,10 +85,12 @@ public class Model extends Observable
     if (tempLen > x)
     {
       tempThingy.reduceLen();
+      totalVisibleLen--;
     }
     else // go forwards
     {
       tempThingy.increaseLen();
+      totalVisibleLen++;
     }
     setChanged();
     notifyObservers();