我正在嘗試根據(jù)隨機(jī)整數(shù)的值更改我擁有的圖像,但是,eclipse 表示 rand 整數(shù)需要一個(gè)主體。我已經(jīng)嘗試過(guò)int rand = random.nextInt(4);但這也行不通。任何幫助將不勝感激。public class GrassTile extends Tile { Random random = new Random(); static BufferedImage texture; int rand; rand = random.nextInt(4); if (rand == 0) { texture = Assets.grass0; } else if(rand == 1) { texture = Assets.grass1; } else if(rand == 2) { texture = Assets.grass2; } else if(rand == 3) { texture = Assets.grass3; } public GrassTile(int id) { super(texture, id); }}謝謝,JavaDev
為什么在 Java 中使用 Random 時(shí)會(huì)出錯(cuò)?
三國(guó)紛爭(zhēng)
2022-06-15 17:01:24