Basically what I have is an actionListener that is called whenever I press a button. The button is in a JDialog that is setVisible(true) when I need it, and setVisible(false) when I don't. In the actionListener I try to create a new object called Tile:
Tile(previewer.pixels, nameValue, (int) hexValue, charValue);
from the constructor
public int[] pixels;
public String name;
public int color;
public char character;
public int id;
public Tile(int[] pixels, String name, int hex, char character) {
this.pixels = pixels;
this.name = name;
this.color = hex;
this.character = character;
this.id = generateId();
}
This creates a new Tile with the attributes of nameValue, hexValue, and charValue, however, for every new tile created the value of "pixels" has the same memory address (I think). So every time I create a new Tile, all of the other tile's value of pixels is equal to the newest one. previewer.pixels is not static, however it changes every time a tile is created. Why would it be doing that? If I pass a variable into a constructor, and the variable changes after the object is created, does it change the objects value?
I tried creating a new array:
final int[] previewerPixels = previewer.pixels;
and passing that into the constructor in Tile, but the same behavior occurred. Is there some property of Java constructors I'm missing? Why would only the one variable of Tile be changing?