0
我从JPanel中创建了一个棋盘。使用的ImageIcon不工作,所以我看了看现场,但是这一切看起来很复杂,我如何将图像添加到一个数组一样将图像添加到数组中JPanel
tiles[0][0].setIcon(br);
这是我的棋盘
创建的JPanelprivate JPanel[][] tiles = new JPanel[6][6];
我已经试过这样:
ImageIcon bn = new ImageIcon("art/BN.gif");
ImageIcon bb = new ImageIcon("art/BB.gif");
ImageIcon br = new ImageIcon("art/BR.gif");
ImageIcon wn = new ImageIcon("art/WN.gif");
ImageIcon wb = new ImageIcon("art/WB.gif");
ImageIcon wr = new ImageIcon("art/WR.gif");
tiles[0][0].add(new JLabel(bn));
tiles[0][1].add(new JLabel(wn));
tiles[0][2].add(new JLabel(wb));
tiles[0][3].add(new JLabel(wb));
tiles[0][4].add(new JLabel(wn));
tiles[0][5].add(new JLabel(wr));
tiles[5][0].add(new JLabel(br));
tiles[5][1].add(new JLabel(bn));
tiles[5][2].add(new JLabel(bb));
tiles[5][3].add(new JLabel(bb));
tiles[5][4].add(new JLabel(bn));
tiles[5][5].add(new JLabel(br));
但它不工作
可以看到面板?你可以看到标签?有什么错误? –
@Fast SnailCant查看标签 – PPasf
ambs的答案是否适合您? –