为什么我的 GUI 在我初始化 ImageIcon 后就消失了?

Why does my GUI disappear as soon as I initialize an ImageIcon?

所以我想在 java 中编写井字游戏。

现在单击一个按钮后,我想将按钮的图像设置为“十字”或“圆形”,但是只要输入以下代码,按钮就会消失,直到我将鼠标悬停在它们上面,然后它们 return.

ImageIcon cross = new ImageIcon("Cross.png");

What it looks like without the code above What it looks like with the code above

Project Structure here

I did in fact use null layot for the window

这就是问题所在。对于 3 x 3 网格,我会使用 GridLayout。有关详细信息,请参阅 How to Use GridLayout