• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timer problem

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I posted this question in the swing section, but it might be more of a threading issue, so I have posted here too.

I've located the source of my earlier timer problem.
The test code shown below works fine:


However, when I modify the mouseReleased method to:


The timer no longer works. (The invokeLater method is there to allow the GUI to repaint itself first, instead of after the code inside the run() method of someRunnableObject completes, which is what tends to happen)

Even better would be to put the timer.start() inside the run() method of the someRunnableObject, but that doesn't work either.

Does anyone know how to resolve this?

Thanks very much for all your help
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an idea:
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much, you've put a lot of effort into that.
I've had a good look at it now...

The problem is I need to repaint the screen after the mouse is released,
since releasing mouse should drop piece into the nearest square.

This is why I was using SwingUtilities.invokeLater(new Runnable...
to let the GUI repaint first before I called the method to search the computers move.

I thought I fixed my previous problem, but the timer isn't working properly, so I might have to try to use what you've done.

Is it possible to do what I said above and repaint inside the mouseReleased method, then call timer.start()?

Thanks
[ May 12, 2006: Message edited by: colin shuker ]
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Caling "repaint" usually does not require the use of "invokeLater". Seems like it would be easy enough to try.
reply
    Bookmark Topic Watch Topic
  • New Topic