我有一个分层窗格,其中包含各种动画。我正在使用 Jlabel (breakB) 在正在破坏的块上显示破坏动画。当块破裂时,问题就出现了。标签应该消失,但它仍然可见。我一直在寻找解决方案几个小时,真的不知道发生了什么,所以任何帮助将不胜感激。
class breakBlock implements ActionListener {
public void actionPerformed(ActionEvent e) {
damageCount+=1;
System.out.println(damageCount);
JLabel breakB = new JLabel();
ImageIcon breakIcon = new ImageIcon();
if(digDown){
blockInt = standingOn;
} else {blockInt = nextTo;}
if(damageCount == 1){
breakIcon = new ImageIcon(break01);
}
if(damageCount == 2){
breakIcon = new ImageIcon(break02);
}
if(damageCount == 3){
breakIcon = new ImageIcon(break03);
}
if(damageCount == 4){
breakIcon = new ImageIcon(break04);
}
if(damageCount == 5){
breakIcon = new ImageIcon(break05);
}
breakB.setIcon(breakIcon);
breakB.setBounds(solidObjects.get(blockInt).getX(), solidObjects.get(blockInt).getY(), breakIcon.getIconHeight(), breakIcon.getIconWidth());
layeredPane.add(breakB, new Integer(2), 0);
if(damageCount == 6){
layeredPane.remove(solidObjects.get(blockInt));
layeredPane.remove(breakB);
layeredPane.repaint(); // sometimes needed
solidObjects.remove(blockInt);
damageCount = 0;
breakBlock.stop();
}
}
}