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 Small problem with method call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Small problem with method call" Watch "Small problem with method call" New topic

Small problem with method call

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Hi, I have a small problem with my rubiks cube.
I want the cube to have all its played moves reversed.

I have a method "undoLastMove()", which graphically undoes a twist applied.
So when I press "Undo" button, this method is called, and everything works fine.

But I also have an "Undo All" button, which basically needs to call that method N times.
But if I do:

It causes a horrible mess, since it doesn't wait for one twist to complete before starting the other, which is what I expected, since they are graphical so they run on AWT thread, I think its called.

I've tried using SwingUtilities.invokeAndWait(Runnable runnable), but I still doesn't work, is there a good way to solve this?

[ April 14, 2007: Message edited by: colin shuker ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you want to see all the undo's?

if so, use a javax.swing.Timer
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Of course, why didn't I think of that.
I had just started to do it recursively. eg

But this is causing a few complications, I think a timer should work well.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
Hmmm, still can't get it to work right, I don't really want a 1 second gap between each undo, but if I set it to say 50ms, then it doesn't complete the first turn in time, since it starts the next turn 50ms later.

Perhaps I need to do it recursivley within the timer somehow?
I agree. Here's the link:
subject: Small problem with method call
It's not a secret anymore!