• Post Reply Bookmark Topic Watch Topic
  • New Topic

Timer problem

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • 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
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an idea:
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Caling "repaint" usually does not require the use of "invokeLater". Seems like it would be easy enough to try.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!