gpt4 book ai didi

java - 2d 图标数组 JAVA 并在 JOptionpane 框中打印

转载 作者:行者123 更新时间:2023-12-01 13:40:06 24 4
gpt4 key购买 nike

如何创建 2d 图标数组并将其打印在 JOptionPane 框中。到目前为止我已经有了这个,但是当我打印出来时它显示了一堆 BlockEmpty.png

public class iconarray{

public static void main (String [] args)


{
Icon blockempty = new ImageIcon("BlockEmpty.png");

Icon Board [] [] = new Icon [8] [8];
String GameBoard = "";
for (int count2 = 2; count2 <= 7; count2++)
{

for (int count3 = 1; count3 <= 7; count3++)
{
Board[count2][count3] = blockempty;
}
}
for (int count2 = 2; count2 <= 7; count2++)
{
for (int count3 = 1; count3 <= 7; count3++)
{
GameBoard = GameBoard + Board[count2][count3];
}
GameBoard = GameBoard + "\n";
}
JOptionPane.showMessageDialog(null, "", "Connect 4", JOptionPane.PLAIN_MESSAGE, blockempty);
}

}

最佳答案

为了显示图标图像,您首先需要某种方式来呈现它。 IconImage 无法自行渲染它们(本身),但需要另一个可以渲染它们的组件。

还有一件事很多人忘记了,JOptionPane 能够显示组件。

例如:

enter image description here

Icon brick = new ImageIcon(BoardOption.class.getResource("/images.jpg"));
JPanel wall = new JPanel(new GridLayout(8, 8, 0, 0));
JLabel bricks[][] = new JLabel[8][8];

for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
bricks[y][x] = new JLabel(brick);
wall.add(bricks[y][x]);
}
}

JOptionPane.showMessageDialog(null, wall, "Another brick in the wall", JOptionPane.PLAIN_MESSAGE, null);

看看How to use icons了解更多详情。

关于java - 2d 图标数组 JAVA 并在 JOptionpane 框中打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20894927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com