Do you see that line
private int[] pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData(); |
You are telling the program to use
to store the image pixels. Everything in Java acts like a pointer reference. So the pixel data for your array is referenced to the same pixel data in your image, therefore all changes you make will be instantly translated. It does not matter where you edit that array, or if you change the name to that array, the pointer will stay the same until you write something like
int[] pixels = new int[4] |
.
and the line where it draws the image...
g.drawImage(img, 0, 0, getWidth(), getHeight(), null); |
Does that clear anything up?