尝试创建一个 gridLayout 并用图像填充它,哪里出错了?
ImageIcon grassIcon = new ImageIcon("images/grass_tile.jpg");
JPanel panel = new JPanel(new GridLayout(haps,snaps,0,0));
JLabel labels[] = new JLabel[(haps*snaps)];
for (int i = 0; i < haps*snaps; i++)
{
labels[i] = new JLabel(grassIcon);
panel.add(labels[i]);
}
frame.add(panel);