Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: I need a different approach - suggestions please Date: Wed, 27 Jun 2012 18:13:00 -0400 Organization: A noiseless patient Spider Lines: 51 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 27 Jun 2012 22:13:02 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="03ebLEozl+tXCe7JS60Feg"; logging-data="27979"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rQXbcxEBMWxsCF/VcX3WC" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: Cancel-Lock: sha1:hHhZkbYnxAyaxsh8zHBXEHY9XIE= Xref: csiph.com comp.lang.java.programmer:15683 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! -- Eric Sosman esosman@ieee-dot-org.invalid