This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Timer problem

 
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
 
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.
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!