I'm having trouble getting the Cards off the table in this card game I'm working on. The cards are JLabels that hold
images of the cards. These JLabels are created dynamically into a JLayeredPane.

I have created some variables to hold the info I believe I need in order to complete this task:

In the declarations setion I have:

public JLabel[][][] playerCard; 

This creates the label with multiple indexes for the player's cards. The first index is the player's position at the
table(Could be from 0 - 5). The second index is the card to be dealt to the player(Could be from 0 - 15) not likely to
ever reach 15, just a precaution and the last index is for the current hand being played(Could be from 0 - 4) as the
player can have 4 hands in play if the player chooses to spit 3 times.

public JLabel[] dealerCard;

This creates a JLabel with only one index for the dealer's cards. It is the card to be dealt to dealer(Could be from 0
- 15)

public Integer cardsPlayed = 0;

This tracks the number of cards played each round.

public JLabel[] cardToRemove = new JLabel[105];

This stores the JLabel that has been created for all cards dealt with this line:

cardToRemove[cardsPlayed] = playerCard[seat][pcard][hand];

I'm using the cardsPlayed as the index to save playerCard[seat][pcard][hand].
For saving the player's cards. Also I'm using:

cardToRemove[cardsPlayed] = dealerCard[dcard];

for the dealer's cards.

After all that info is collected and the hands are played and new game is clcked, I have this:

for(int i = 0; i < cardsPlayed; i++){
                Pane.remove( cardToRemove[i]);

This appears to be working but the labels are still visible in the Pane. Can't figure out what I'm doing wrong.

2 Years
Discussion Span
Last Post by henryz_box

For anyone having this same issue I found the solution. this is my modified code:

 for(int i = 0; i < cardsPlayed; i++){
                Pane.remove( cardToRemove[i]);

I hope this helps someone.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.