java - All my objects change in my arraylist -
I am adding a new object (class) to ArrayList
, but when I try Receive variables from objects in my
This is my code for loop. Print says that every variable in the object [i] has the same number.
Arrielist Treats; Array list branch list; Boolean clicked; Zero setup () {size (1024, 768, P3); Click = pane; Triadots = new arrives (); BranchList = new Arrayist (); Tree dot.ed (new tidad (width / 2, height / 2)); } Zero draw () {if (click) AddTreeDot (); If (tree dots.) (1) {for (int i = 0; i & lt; tridotes.syge () -1; i ++) {int temp_lock = 0; Treated Index 1 = (Tredot) Tridots.Tet (I); Treadt Index 2 = (Tridot) Tridutes. Gat (I + 1); Print (index1.xLoc (temp_loc) + ""); Print (i + ""); Print (index2.xLoc (temp_loc) + ""); Print (i + ""); StrokeWeight (2); Stroke (# 09FF00); Line (index1.xLoc (temp_loc), index 1. yol (temp_loc), index2.xLoc (temp_loc), index2.yLoc (temp_loc)); }}} Zero AddTreeDot () {int randomX = 0; Int random y = 0; Tree dot.ed (new triadot (random dot x (random x), random dot (randial y)); Click = pane; } Int randomDotX (int _randomX) {triadot temp = (triadot) tridettset. Tate (Trydots. (- -1); Int temp_x_loc = 0; Int lastDotX = temp.xLoc (temp_x_loc); _randomX = lastDotX + int (random (10, 10)); return _randomX;} Int randomDotY (int _randomY) {TreeDot temp = (TreeDot) treeDots.get (treeDots.size () -1); Int temp_y_loc = 0; Int lastDotY = temp.yLoc (temp_y_loc); _randomY = last DotY + int (random (0, 10)); return _randomY;} void mouseClicked () {clicked = true;}
and here is my class code
int randomSpread; Boolean Keaijiro, Boolean and dot ; Int x_loc; Int y_loc; Int Lainticnes; Class Tree dot {Trydot (on Int x_loc_, Int y_ on loc_) {x_loc = x_loc_par; Y_loc = y_loc_par; // oval (x_loc_par, y_loc_par, 10, 10); EndDot = false;} Int xLoc (int _x_loc) {_x_loc = x_loc; return _ x_loc;} Int yLoc (int _y_loc) {_y_loc = y_loc; return _y_loc;}}
the problem is to declare a variable inside the classroom and amp; this code will be accurate.
int xLoc (int _x_loc) {_x_loc = x_loc; Return _x_loc; } Int yLoc (int _y_loc) {_y_loc = y_loc; Return _y_loc; }
Then in the call
int temp_loc = 0; Treated Index 1 = (Tredot) Tridots.Tet (I); Treadt Index 2 = (Tridot) Tridutes. Gat (I + 1); Print (index1.xLoc (temp_loc) + ""); Print (i + ""); Print (index2.xLoc (temp_loc) + ""); Print (i + "");
This line index1.xLoc (temp_loc)
reset the value to 0 for you.
Comments
Post a Comment