Win a copy of Spring Boot in Practice this week in the Spring forum!

Shafin Jadavji

+ Follow
since Nov 10, 2003
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shafin Jadavji

Thank you for the help. I changed my code and it worked perfectly where each card gets drawn afew seconds after each other. I also went ahead and performed the updateHand method a few more times so I could display the rest of the cards in the player and dealer's hands.
But now I have another question. Is ther a way to know if the cards have been repainted so I can update a status label. I have another class that is the Model (in a MVC design where the previouse Applet is the View) which sends a message (by being observable and the JApplet implementing obeserver) back to the applet, who the winner was. I want to take this message and display it on a JLabel I have on the applet, but I only want to do it after all the cards are drawn. So is there a way to tell if the cards have already been painted before I update the status.
I tried using a
while(whatEverTheUpdateHandThreadIsCalled.isAlive()) {
//do nothing
But that brings me back to the same problem I had before in that the Applet waits for the thread to die before it can repaint. So once again I get all the cards drawn at the same time. Remember I want to wait a couple of seconds while drawing each card.
Do you have any ideas on what I can do.
Also I am sorry for posting this on the wrong section of the forum. I guess I should have placed it on the Thread section of the forum.
[ November 11, 2003: Message edited by: Shafin Jadavji ]
18 years ago
I'm building a blackjack applet game and am having problems with waiting a few seconds before I display each card(a new JLabel with Icon) to the screen. I have a CardPanel class which extends JLayerdPane which I create 2 instances of(one for dealer and one for player) in the main applet. I also have a Thread.sleep(2000) in the updateHand method in the CardPanel (which gets called by a button in the main applet)that I want to wait 2 seonds before creating a new JLabel with an ImageIcon for the players card and then wait another 2 seconds before doing the same for the dealers card. But instead I get a 4 second wait and both cards are drawn at the same time.
As you can tell by the code I'm a java newbie so if I am using thread totally wrong please let me know.

Here's the code for the Applet

I'm not sure how to add the image to this post but any gif should work if renamed to blank.gif or I can email the gif I used.
[ November 10, 2003: Message edited by: Shafin Jadavji ]
18 years ago