我正在构建一个内存匹配游戏,在ActionListener中我想在发现一个块之前实现一个动画gif,但是gif从未显示过,我认为它会重置;我该如何解决这个问题?
for(int i = 0; i< buttonNum; i++)
{
if(e.getSource() == button[i])
{
try
{
URL blockIcon = this.getClass().getClassLoader().getResource(block[i].toString());
//sets it to the gif
button[i].setIcon(uncoverBlock);
Thread.sleep(5000);
button[i].setIcon(new ImageIcon(blockIcon));
System.out.println("Block: " + block[i]);
currentIndex = i;
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
}