Reputation: 7202
I have a project written using Swing, and I want to make it more smoothly (like JavaFX is) by adding animation to some components(JButton
, JScrollPane
, JSplitPane
) using javax.swing.Timer
.
That is not a game. I want to use the Timer
for short animations like mouseHover events, dropdown, or scroll. But the problem is, a lot of Timer objects should be created.
Question: What action does it perform for JVM? I would start and stop a lot of Timers during app session.
Upvotes: 1
Views: 443
Reputation: 15408
What action does it perform for JVM? I would start and stop a lot of Timers during app session.
Swing Timer
fires ActionEvents
at specified intervals to animate object providing function: start(), stop(), restart(), and most importantly setDelay(int delay)
to fire successive action events in specific inerval ensuring all such event task are executed in the EDT(event dispatch thread). Waiting state of All created Timers
are managed by a single shared thread, TimerQueue
, created by the first Timer
object that executes.
Handling timer
might be tedious. Instead of writing same Timer
handling code every time, I would go for using a library instead like swing TimingFrameWork.
Upvotes: 2
Reputation: 109815
That is not a game. I want to use the Timer for short animations like mouseHover events, dropdown, or scroll. But the problem is, a lot of Timer objects should be created.
this is job only for one Swing Timer
together with (mouseHover events, dropdown, or scroll) focus from mouse or key_events
, Swing Timer
has implemented start()
, stop()
and restart()
, last one is important for waiting until users action ended
logically isn't possible to generating more than one event, different situation will be in the case that there is multitouch display, and in this case is only one event important too, rest of events are directions, scalling, factor, etc...
Upvotes: 2