I had originally begun my project (a game) using the javax.swing.Timer animation loop documented at My game has different difficulty levels--the higher the difficulty, the shorter the delay--and I had been setting this timer based on the difficulty level. However, I also want to have a custom time keeper (not to be confused with the other Timer classes) which keeps track of how much time the player has left to make a move. I want to display a panel that updates every 80 milliseconds or so, showing a horizontal bar that represents the amount of time left (this bar would shrink over time).
Because the time keeper is independent of the original Timer loop, I tried making the time keeper its own Runnable JPanel and wrapping a thread around it. (Examples for this method can be found at among others.) This resulted in both the javax.swing.Timer (which is event-based, but must surely use an internal Thread implementation) and the new time keeper Thread being run simultaneously. It almost works... I can see the time keeper update and i can see the player move around the board in the animation loop, however it seems that somehow the player's movements are drawn in both the main board JPanel and the time keeper JPanel. This is naturally impossible, as a Component can only belong to one Container at a time.
So naturally something seems amiss.
Do I have to rely on only one method of animation? If so, which would you recommend? Is there another time keeper class I can use (sort of like a reverse progress bar) which can update itself independently of the animation loop? Any suggestions would be greatly appreciated.
Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
Because the time keeper is independent of the original Timer loop, I tried making the time keeper its own Runnable JPanel and wrapping a thread around it. (Examples for this method can be found at among others.) This resulted in both the javax.swing.Timer (which is event-based, but must surely use an internal Thread implementation) and the new time keeper Thread being run simultaneously. It almost works... I can see the time keeper update and i can see the player move around the board in the animation loop, however it seems that somehow the player's movements are drawn in both the main board JPanel and the time keeper JPanel. This is naturally impossible, as a Component can only belong to one Container at a time.
So naturally something seems amiss.
Do I have to rely on only one method of animation? If so, which would you recommend? Is there another time keeper class I can use (sort of like a reverse progress bar) which can update itself independently of the animation loop? Any suggestions would be greatly appreciated.
Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."