Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30402

Re: Could this be done better

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.roellig-ltd.de!open-news-network.org!fbe002.ams.xsnews.nl!feed.xsnews.nl!border04.ams.xsnews.nl!feeder02.ams.xsnews.nl!frontend-F09-05.ams.news.kpn.nl
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>
X-Face "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR<J%a^F2lh4[N~Yz4 nSp#c+aQo1b5=?HcNEkQ7QzF<])O3X4MDL/AYjys&*mt>,v+Pti8=Vi/Z"g^?b"E
X-Homepage http://www.decebal.nl/
Date Tue, 25 Nov 2014 00:12:50 +0100
Message-ID <877fyk6vm5.fsf@Equus.decebal.nl> (permalink)
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)
Cancel-Lock sha1:ZxyaTQiW60m2GzrBerO1aDV/lPY=
MIME-Version 1.0
Content-Type text/plain
Lines 42
NNTP-Posting-Host 77.171.42.144
X-Trace 1416870835 news.kpn.nl 21160 77.171.42.144@kpn/77.171.42.144:54109
Xref csiph.com comp.lang.java.programmer:30402

Show key headers only | View raw


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


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