File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JButtons switching states(icons) too quickly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButtons switching states(icons) too quickly" Watch "JButtons switching states(icons) too quickly" New topic

JButtons switching states(icons) too quickly

A Parent

Joined: May 18, 2005
Posts: 9
I have a simple memory game that I've been trying to debug. It allows the user to flip two cards, compares them, if they are a match they stay up, otherwise get flipped back over. Problem is, for the second card flipped, it next does the comparison so quickly, it doesn't seem that the second card was ever displayed.

Any ideas on how to fix this, or is there something I'm missing? I spent most of the day on sun's website trying to figure out threads and sleep vs wait... you can tell I'm not an expert. TIA!

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Remove all other thread code, start a new thread inside the 'checkForMatch' method,
begin the run method with the desired delay, proceed with checking...

[ May 18, 2005: Message edited by: Craig Wood ]
A Parent

Joined: May 18, 2005
Posts: 9
thank you! Can't tell you how long I looked at thread samples but wasn't sure how to integrate them into my own code. I also found the Timer method, which worked too.

Now it's not working as I try to convert to an applet, I have changed the constructor to init, removed the setSize, setTitle calls... it's saying there's a Java IO access Permission error? I'll do a little more research and then post a new thread in applets.
[ May 20, 2005: Message edited by: A Parent ]
I agree. Here's the link:
subject: JButtons switching states(icons) too quickly
It's not a secret anymore!