嗨,我对 java 很陌生。我需要为游戏命名 Ratsuk 女巫很像国际象棋,但它只有骑士。因此,当骑士不再有移动的空间时,玩家就输了。
我为此做了一系列按钮
import java.awt.*;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Tablero {
    private JButton[][] mesa;
    public Tablero() {
        mesa = new JButton[8][8];
    }
    public void cuadriculado(JFrame ventana) {
        JPanel panel = new JPanel(new GridLayout(8, 8, 4, 4));
        for (int i = 0; i < mesa.length; i++) {
            for (int j = 0; j < mesa[0].length; j++) {
                mesa[i][j] = new JButton();
                mesa[i][j].setPreferredSize(new Dimension(40, 40));
                panel.add(mesa[i][j]);
            }
        }
        for (int r = 0; r < mesa.length; r++) {
            for (int t = 0; t < mesa[0].length; t++) {
                if (r % 2 == 0 || r == 0) {
                    if (t % 2 == 0 || t == 0) {
                        mesa[r][t].setBackground(Color.BLACK);
                    } else {
                        mesa[r][t].setBackground(Color.WHITE);
                    }
                } else {
                    if (t % 2 == 0 || t == 0) {
                        mesa[r][t].setBackground(Color.WHITE);
                    } else {
                        mesa[r][t].setBackground(Color.BLACK);
                    }
                }
            }
        }
        ventana.setContentPane(panel);
        ventana.setSize(500, 500);
        ventana.setVisible(true);
        Icon image = new ImageIcon(getClass().getResource("redKnight.gif"));
        mesa[0][0] = new JButton(image);
    }
}
该文件编译但我试图在按钮 mesa[0][0] 中设置的图像没有出现。我怎样才能解决这个问题?