Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Small problem with method call  RSS feed

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks
[ April 14, 2007: Message edited by: colin shuker ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you want to see all the undo's?

if so, use a javax.swing.Timer
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!