Java 为什么每次我创建一个对象数组的新元素时,之前创建的元素都具有与新元素相同的属性

Java 为什么每次我创建一个对象数组的新元素时,之前创建的元素都具有与新元素相同的属性,java,arrays,Java,Arrays,我创建了一个名为Tile的类,它通过为图像提供一个图像、x位置、y位置、宽度、高度和图形对象来向屏幕渲染图像。该类的代码如下: package tile; import java.awt.Graphics; import java.awt.image.BufferedImage; import image.Assets; public class Tile { public static int x, y, width, height; public static BufferedImag

我创建了一个名为Tile的类,它通过为图像提供一个图像、x位置、y位置、宽度、高度和图形对象来向屏幕渲染图像。该类的代码如下:

package tile;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import image.Assets;

public class Tile {

public static int x, y, width, height;
public static BufferedImage image;
Graphics graf;
public static int id;



public Tile(int tx, int ty, int twidth, int theight, Graphics g, BufferedImage timage, int tId)
{
this.width = twidth;
this.x = tx;
this.y = ty;
this.image = timage;
this.graf = g;
this.height = theight;
this.id = tId;

}

 public void render()
{ 

this.graf.drawImage(this.image, this.x, this.y, this.width, this.height, null);

}
//And then here are the getters and setters methods...
我想创建一个对象平铺数组,其中该数组的每个元素都有不同的属性。 所以我在另一个类中编写了这段代码:

...
Tile []t = new Tile[216];
for(int i = 0; i < 100; i++)
{
 t[i] = new Tile(x, y, width, height, graphic, image, id)
 t[i].render();
}
...
。。。
瓷砖[]t=新瓷砖[216];
对于(int i=0;i<100;i++)
{
t[i]=新瓷砖(x、y、宽度、高度、图形、图像、id)
t[i].render();
}
...
但每次它在这个数组中创建一个新的平铺对象时,在这个对象之前创建的另一个对象的属性与新创建的对象相同。 我的错误在哪里?
谢谢你的回答,请原谅我的英语不好。

不要使用静态变量。而不是写作

public static int x, y, width, height;
public static BufferedImage image;
public static int id;
试一试


静态变量是全局变量,这意味着它们由所有实例共享。这就是为什么在创建新实例时会覆盖属性。

不要使用静态变量。而不是写作

public static int x, y, width, height;
public static BufferedImage image;
public static int id;
试一试


静态变量是全局变量,这意味着它们由所有实例共享。这就是为什么在创建新实例时会覆盖属性。

类中有
静态
属性。属性是静态的,并且在构造函数中分配给它们。从它们中删除
static
。您的类中有
static
属性。您的属性是静态的,并且在构造函数中分配给它们。从它们中删除
static