Procházet zdrojové kódy

Fixed another arrayIndexOutOfBounds

Ludwig Tietze před 6 roky
rodič
revize
eac7a8a254
2 změnil soubory, kde provedl 9 přidání a 3 odebrání
  1. 6 1
      src/ui/model/Model.java
  2. 3 2
      src/ui/view/UnitGraph.java

+ 6 - 1
src/ui/model/Model.java

@@ -26,7 +26,8 @@ import java.util.List;
  */
 public class Model {
 
-    private static final int ITERATIONS = 100;
+	
+    private static final int GRAPH_ITERATIONS = 100;
     // Global Variables
     private static int sCALE = 50; // Picture Scale
     private static int sCALEdIV2 = sCALE / 2;
@@ -945,6 +946,10 @@ public class Model {
 	public void setFairnessModel(short fairnessModel) {
 		this.fairnessModel = fairnessModel;
 	}
+	
+	public int getGraphIterations(){
+		return GRAPH_ITERATIONS;
+	}
 
 	/**
      * Initialize the Gson with wanted parameters

+ 3 - 2
src/ui/view/UnitGraph.java

@@ -128,11 +128,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
                 }
 
                 // Iteration Value
-                textWidth = g.getFontMetrics().stringWidth("" + arrayOfFloats[model.getCurIteration()]) + 2;
+                //TODO: added function getGraphIterations see if it works
+                textWidth = g.getFontMetrics().stringWidth("" + arrayOfFloats[model.getCurIteration()%model.getGraphIterations()]) + 2;
                 if (textWidth
                         + (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1) + 2
                         + border <= this.getWidth()) {
-                    g2.drawString("" + arrayOfFloats[model.getCurIteration()],
+                    g2.drawString("" + arrayOfFloats[model.getCurIteration()%model.getGraphIterations()],
                             (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
                                     + 2 + border,
                             this.getHeight() - 10);