Path: csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jerry Stuckle Newsgroups: comp.lang.java.programmer Subject: Re: ActionEvent Generator Date: Mon, 02 Feb 2015 09:43:51 -0500 Organization: A noiseless patient Spider Lines: 51 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 2 Feb 2015 14:43:18 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="3088393e34bc61b3e6a923d0c81ae1e3"; logging-data="17210"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Ud/ohADut1d0HhX6DJyLcDaEL2OZrzlo=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 In-Reply-To: Cancel-Lock: sha1:xZKcypslMo5mEQbyZhaBAt/dVRE= Xref: csiph.com comp.lang.java.programmer:31014 On 2/1/2015 8:27 PM, Thomas Richter wrote: > On 02.02.2015 01:49, Jerry Stuckle wrote: >> Hi, all, >> >> I have a need to generate an ActionEvent to drive handlers, and am >> having trouble finding examples. It doesn't seem to be as easy as a >> PropertyChangeEvent, for which there are multiple examples. I've also >> looked at some of the Java source code and it seems somewhat convoluted. >> >> I don't need something real fancy - just the ability to generate an >> ActionEvent in my object and have it passed to the handlers. Can anyone >> point me to some example code showing an easy way to do this? > > It's actually quite trivial. You create a new ActionEvent() with > > ActionEvent ev = new ActionEvent(...); > > and then have a list of actionListeners, for example in your class as an > arraylist > > ArrayList alist = new ArrayList(); > > and simply iterate over the list, calling actionPerformed() for each > listener: > > for(al : alist) { > al.actionPerformed(ev); > } > > Done. It's really that trivial. > > Greetings, > Thomas > > Thomas, Hmmm, this is just too easy! :) I looked through a lot of code, i.e. Node, MenuItem and several others, and the code looked much more complex. Of course I'll need to add a few extra methods, but this gets me on the right track and I think I can handle the rest. Thanks! -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================