how am i adding delay for couple secounds in java

45 Views Asked by At

Hi i created a black jack game, when i showing the dealer card i want to add a delay of couple seconds before showing each card, hope my code is clear enough, appreciate any help

private void standBtnActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        System.out.println("DEALER CARD COUNT --- " + dealerCardCount);
        dealerCard1.setIcon(new javax.swing.ImageIcon(getClass().getResource(dealerHand[0].img))); // flipping dealer first card
        dealerHandSum = calculateHand(dealerHand, dealerCardCount);
        jTextSumDealer.setText(String.valueOf(dealerHandSum));
        int count = 0;        
        
        while(dealerHandSum < 17){ // hiiting a card
           dealerCardCount++; // add card to the dealer
           dealerHand[dealerCardCount] = getCard();
           if(dealerCardCount == 2){ // if its the delaer 3rd card so setting the 3rd lable(card count start from 0)
                dealerCard3.setIcon(new javax.swing.ImageIcon(getClass().getResource(dealerHand[dealerCardCount].img)));
           }
           else if(dealerCardCount == 3){
                dealerCard4.setIcon(new javax.swing.ImageIcon(getClass().getResource(dealerHand[dealerCardCount].img)));
           }
           else if(dealerCardCount == 4){
                dealerCard5.setIcon(new javax.swing.ImageIcon(getClass().getResource(dealerHand[dealerCardCount].img)));
           }
           dealerHandSum = calculateHand(dealerHand, dealerCardCount);
            jTextSumDealer.setText(String.valueOf(dealerHandSum));
        }

        if(playerHandSum > dealerHandSum){
            //bp.wallet = bp.wallet - betSum;
            Component frame = null;
            JOptionPane.showMessageDialog(frame,"YOU WON!", "A plain message", JOptionPane.INFORMATION_MESSAGE);
        }
        else if(playerHandSum == dealerHandSum){
            //bp.wallet = bp.wallet - betSum;
            Component frame = null;
            JOptionPane.showMessageDialog(frame,"PUSH!", "A plain message", JOptionPane.INFORMATION_MESSAGE);
        }
        else if(dealerHandSum < 22) {
            Component frame = null;
            JOptionPane.showMessageDialog(frame,"YOU LOST...", "A plain message", JOptionPane.INFORMATION_MESSAGE);
        }
        resetGame();
        
    }                      
0

There are 0 best solutions below