java - Manipulate a single element of vector -
I am currently trying to manipulate an element of a vector in Java. If I try to do this with element (A) or get (i) in a loop, then the whole vector still changes. I am still trying to do this by using vectors and trying to do it (as I use them throughout my program).
I have tried to clone my vector in a temporary one, then remove all the elements of the vector except for tampering, but there is no benefit.
Here is my code section:
@ Override Public Empty Paint Coment (Graphics G) {super.paintComponent (g); Graphics 2DG2 = (Graphics 2D) G; For (int i = 0; i & lt; shapes.size (); i ++) {if (shapes .gate (i)! = Null) {g2.setColor (color-selected ()); If (fill.is selected () & amp;! (String) shapes list.getSelectedItem () == "line") {g2.fill (shapes.elementAt (i)); } Other {g2.draw (figures. Element (i)); The problem that is happening is that I want to fill / draw / change the color of the next element drawn in my temporary paint program, but it changes every size. . Any tips (or an explanation as to why this is happening) will be greatly appreciated.
The most common reason for this problem is that figures
actually have many shapes , But only one reference to the same size object. The bug then will be in the part of the code that fills the vector.
SidNote: vector is old and obsolete; it should be avoided in favor of ArrayList
, unless you are using that API Which really demands the vector
(which is in the swing). If you are using tutorials or books that teach you to use the vector
, then they are more than 10 years old and they should be avoided.
Comments
Post a Comment