This is a part of the code that makes up the health system for my ship for an arcade shooter game in Java. Each heart represents one life to the ship. The ship has 3 lives which would mean 3 hearts shows up on the screen. If the ship lose all 3 lives, the ship is destroyed. The removeHeart method is called when the ship has a valid collision on an object. The code I commented out does not remove the hearts in real time but the one that set the hearts invisible does remove hearts in real time. I am confuse why the remove method does not animate the hearts in real time because I am specifying the correct ship heart label. The remove method winds up doing is remove all the hearts from the array when the ship is destroyed.
// remove the heart of the given current heart index
public void removeHeart(int currentHeartIndex)
{
// the following commented code apparently does not make the heart disappear when the ship takes a hit
//getHeartPanel().remove(shipHeartLabel[currentHeartIndex]);
// this is the current workaround to removing the hearts
shipHeartLabel[currentHeartIndex].setVisible(false);
}