Ver Fonte

trying to do this a diff way

tarfeef101 há 6 anos atrás
pai
commit
56c7c4ad7f
1 ficheiros alterados com 15 adições e 1 exclusões
  1. 15 1
      assignments/a2/src/main/java/Model.java

+ 15 - 1
assignments/a2/src/main/java/Model.java

@@ -85,13 +85,27 @@ public class Model extends Observable
   
   public void changeThingy(int x) // int x is the position in the slider we are at
   {
-    int tempLen = 0;
+    /*int tempLen = 0;
     int index = 0;
     
     for (int i = 0; i < thingies.size() && tempLen <= x; i++)
     {
       tempLen += thingies.get(i).getVisibleLen();
       index = i;
+    }*/
+    
+    
+    int index = 0;
+    int tempLen = 0;
+    while (tempLen <= totalVisibleLen)
+    {
+      if ((totalVisibleLen - thingies.get(i).getVisibleLen()) < 0)
+      {
+        break;
+      }
+      
+      tempLen += thingies.get(index).getVisibleLen();
+      ++index;
     }
     
     //if (Math.abs(index - thingies.indexOf(curThingy)) > 1 && index != (thingies.size() - 1)) index = thingies.indexOf(curThingy);