paint() problem
I'm having a paint problem. In the Blackjack game i'm designing, I want an animation to take place so that a card can be seen moving from the deck and into the dealer's/player's hand. Here is the source for the class.
class CardPanelextends JPanel
{
private BufferedImage animationCard =null;
privateint animX = 350;
privateint animY = 200;
private BufferedImage deckPic =null;
private BufferedImage dealerCard1 =null;
private BufferedImage dealerCard2 =null;
private BufferedImage dealerCard3 =null;
private BufferedImage dealerCard4 =null;
private BufferedImage dealerCard5 =null;
private BufferedImage playerCard1 =null;
private BufferedImage playerCard2 =null;
private BufferedImage playerCard3 =null;
private BufferedImage playerCard4 =null;
private BufferedImage playerCard5 =null;
public CardPanel()
{
setPreferredSize(new Dimension(500,600));
try
{
deckPic = ImageIO.read(new File("cards/card_deck.JPG"));
dealerCard1 = ImageIO.read(new File("cards/card_back.JPG"));
animationCard = dealerCard1;
}catch(IOException crap)
{
System.out.println("Missing graphics file, terminating..");
System.exit(0);
}
repaint();
}//end CardPanel c'tor
//**************************************************************
publicvoid paint(Graphics g)
{
//draw animation (wherever it is)
g.drawImage(animationCard,animX,animY,null);
//draw deck
//g.drawImage(deckPic,350,200,null);
//draw dealer cards
g.drawImage(dealerCard1,50,10,null);
g.drawImage(dealerCard2,70,10,null);
g.drawImage(dealerCard3,90,10,null);
g.drawImage(dealerCard4,110,10,null);
g.drawImage(dealerCard5,130,10,null);
//draw user cards example
g.drawImage(playerCard1,50,450,null);
g.drawImage(playerCard2,70,450,null);
g.drawImage(playerCard3,90,450,null);
g.drawImage(playerCard4,110,450,null);
g.drawImage(playerCard5,130,450,null);
System.out.println("Paint running");
}//end paint()
//**************************************************************
publicvoid animateHit(String playerOrDealer,int numCardsInHand,
Card c)
{
if (playerOrDealer =="player")
{
if (numCardsInHand == 1)
{
while (animY != 450)
{
System.out.println("Looping, animY = " + animY);
animY += 2;
try
{
Thread.sleep(50);
}catch(InterruptedException ie)
{
System.exit(0);
}
//repaint();
this.repaint();
}//end while
}
}//end "player" if
}//end animateHit()
//****************************************************************
}//end class CardPanel
Here is the method that will actually be calling this panel's paint method.
NOTE: IT IS IN A DIFFERENT PANEL!!
publicvoid actionPerformed(ActionEvent e)
{
Object o = e.getSource();
if (o == deal)
cp.animateHit("player",1,deck.cards[0]);
}
If you look in the paint method, I write a line to print out a statement to notify that the paint method is indeed running. It definitely doesn't run as many times as it should, so I believe that when I call animateHit(), a differen't panel's Paint() method is being called. How can I resolve this? I'll need to call the method from another panel. I've already tried using thethis keyword.

