【发布时间】:2013-12-18 05:54:23
【问题描述】:
我当前的代码有趣地与另一个 IDE(JGrasp)一起工作,尽管我目前正在尝试创建一个使用网络的游戏。 Eclipse 允许在单台计算机上联网。出于某种原因,我发布的这个方法将想象添加到 JLabel 数组中,不适用于 eclipse?我是 eclipse 新手,不知道为什么会这样?
private JPanel createBoard()
{
// Instantiate Panel with a GridLayout
board = new JPanel();
board.setLayout(new GridLayout(10,10));
// Fill the Panel with an Array of Labels
// Checks for exception
boardSpotArray = new JLabel[100];
try
{
for (int x = 0; x < boardSpotArray.length; x++)
{
boardSpotArray[x] = new JLabel();
boardSpotArray[x].setIcon(new ImageIcon(x + ".jpg"));
board.add(boardSpotArray[x]);
}
}
catch (IndexOutOfBoundsException exception)
{
System.out.println("Array drawer not available, " + exception.getMessage());
}
// return panel
return board;
}
【问题讨论】:
-
x的String文件路径是什么? -
怎么不工作了?你遇到了什么错误?
-
图像与类位于同一文件中。每个图像被命名为 0.jpg、1.jpg 等。
-
没有出现错误,没有显示任何内容,但在其他 IDE 中它们是图像。