1
林显示图片的8X8格的新游戏,这些照片都是随机使用二维数组的Math.random()什么是正确的update()方法为我的GUI(JAVA)
有地方也是一款“新游戏”按钮,我希望用户无需打开新的GUI即可刷新页面,并重新显示网格。
这是我用来显示网格
for (int r = 0; r < ShinyButtons.ROWS; r++){
for (int c = 0; c < ShinyButtons.ROWS; c++) {
newbuttonTable[r][c] = new JButton(icons[(int) (Math.random()*7)]);
newbuttonTable[r][c].setLocation(10+c*69, 10+r*69);
newbuttonTable[r][c].setSize(69, 69);
add(newbuttonTable[r][c]);
}
考虑使用'GridLayout(...)'而不是手动将按钮与'setBounds'放在一起。除此之外:您可以通过调用removeAll()来移除此面板上的所有按钮(但不确定这是否是您要求的) – Marco13