Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30402
| From | Cecil Westerhof <Cecil@decebal.nl> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Could this be done better |
| Organization | Decebal Computing |
| References | <87zjbg97c5.fsf@Equus.decebal.nl> <m4vf1f$j03$1@dont-email.me> <87ppcc8s3i.fsf@Equus.decebal.nl> <m4vu6i$vkg$1@dont-email.me> |
| Date | 2014-11-25 00:12 +0100 |
| Message-ID | <877fyk6vm5.fsf@Equus.decebal.nl> (permalink) |
Op Monday 24 Nov 2014 19:42 CET schreef Eric Sosman: >>> - Use javax.swing.Timer instead of java.util.Timer. The >>> mechanics are a bit different -- you write an ActionListener >>> instead of subclassing TimerTask -- but the action listener >>> automatically runs on the EDT, where it's safe to manipulate >>> your GUI. >> >> Or is there a reason why did would be better? > > (Shrug.) For your purpose I don't see much difference. > But suppose you wanted to add a few more buttons to your GUI: > > "Next colour" > "Previous colour" > "Start cycling" > "Stop cycling" > > You'll need an ActionListener for the "Next colour" button, > and with javax.swing.Timer you could re-use that exact same > ActionListener for cycling. Essentially, the Timer would fire > the same kind of events the button does, and they'd be handled > by the same chunk of code. > > The JavaDoc for javax.swing.Timer mentions another possible > advantage: If you have a *lot* of timed activity in your GUI, > you might wind up creating a *lot* of java.util.Timer threads if > you weren't careful. With javax.swing.Timer that's not an issue; > javax.swing.Timer "multiplexes" all the different events on a > single internal thread. FWIW, I myself have never created so > many Timers (of either kind) that thread multiplicity ever began > to become a problem, but, hey ... > > An even more flexible and feature-ridden alternative would be > to use java.util.concurrent.ScheduledThreadPoolExecutor. Looks like I have some experimenting to do. :-D -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-24 12:16 +0100
Re: Could this be done better "Qu0ll" <Qu0llSixFour@gmail.com> - 2014-11-24 22:49 +1100
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-24 17:54 +0100
Re: Could this be done better Knute Johnson <eternal@knutejohnson.com> - 2014-11-24 09:37 -0800
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-24 19:27 +0100
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-24 09:23 -0500
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-24 17:45 +0100
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-24 13:42 -0500
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-25 00:12 +0100
Re: Could this be done better Knute Johnson <eternal@knutejohnson.com> - 2014-11-24 09:19 -0800
Re: Could this be done better Knute Johnson <eternal@knutejohnson.com> - 2014-11-24 09:41 -0800
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-25 00:55 +0100
Re: Could this be done better Cecil Westerhof <Cecil@decebal.nl> - 2014-11-25 00:11 +0100
Re: Could this be done better Knute Johnson <eternal@knutejohnson.com> - 2014-11-24 16:26 -0800
Re: Could this be done better Brixomatic <brixomatic@yahoo.com> - 2014-11-25 19:58 +0100
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-25 14:36 -0500
Re: Could this be done better Brixomatic <brixomatic@yahoo.com> - 2014-11-26 01:58 +0100
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-26 08:48 -0500
Re: Could this be done better Brixomatic <brixomatic@yahoo.com> - 2014-11-29 19:43 +0100
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-29 15:44 -0500
Re: Could this be done better Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-11-29 15:47 -0500
csiph-web