Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: bilsch Newsgroups: comp.lang.java.programmer Subject: Re: I need a different approach - suggestions please Date: Wed, 27 Jun 2012 18:48:59 -0700 Organization: A noiseless patient Spider Lines: 48 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 28 Jun 2012 01:48:58 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="KnXAleWiR2b1CH/F67mjfA"; logging-data="531"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18eb4nFvraVuBO+b4HCC7Pe" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 In-Reply-To: Cancel-Lock: sha1:R/qJP9WQemeq2BbBi/h4GbH3of0= Xref: csiph.com comp.lang.java.programmer:15695 On 6/27/2012 3:13 PM, Eric Sosman wrote: > On 6/27/2012 5:44 PM, bilsch wrote: >> On 6/26/2012 2:21 PM, Eric Sosman wrote: >>> [...] >>> You needn't use the same listener for the 7 key as for >>> the Backspace key ... >>> >> The listeners all call a statement in the second file: >> >> public void actionPerformed(ActionEvent event) >> >> so I don't understand how a button listener can be different from >> another button listener. >> >> Could you explain please? > > In your code there's a class called CrunchQ1, and because it > implements the ActionListener interface you can (and do) tell > your buttons to use an instance of that class as their action > listeners: > > CrunchQ1 crunchNu = new CrunchQ1(this); > ... > dot.addActionListener(crunchNu); > zro.addActionListener(crunchNu); > one.addActionListener(crunchNu); > ... > > What I'm suggesting is that you could perfectly have another > class, maybe CrunchQ2, that also implements ActionListener but does > something different in its ActionPerformed method. Then you could > make yourself an instance of the CrunchQ2 class, and use it instead > of the CrunchQ1 instance for some of your buttons: > > CrunchQ1 crunchNu = new CrunchQ1(this); > CrunchQ2 dotty = new CrunchQ2(...whatever...); > ... > dot.addActionListener(dotty); > zro.addActionListener(crunchNu); > one.addActionListener(crunchNu); > ... > > If you have other buttons with idiosyncratic behaviors, you > could give them their own ActionListener implementations, too. > There is no reason in the world why every button in your program > should share the same listener! > Thanks for the info.