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 14:44:26 -0700 Organization: A noiseless patient Spider Lines: 47 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 21:44:25 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="SCMsXqyEgNCKlTC+UnaBHg"; logging-data="17651"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1849XzBpbBBd9NXHI9W5J/q" 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:ke7UNGnYnZID4YCFgPX5CbKU7Dg= Xref: csiph.com comp.lang.java.programmer:15680 On 6/26/2012 2:21 PM, Eric Sosman wrote: > On 6/26/2012 4:04 PM, bilsch wrote: >> On 6/25/2012 6:10 PM, markspace wrote: >>> [...] >>> BTW, another way to improve you code is to watch the big cascades of >>> if-else statements. For example this: >>> >>> if (btn == ".") {strng1 += btn;} >>> else if (btn == "0") {strng1 += btn;} >>> else if (btn == "1") {strng1 += btn;} >>> else if (btn == "2") {strng1 += btn;} >>> else if (btn == "3") {strng1 += btn;} >>> else if (btn == "4") {strng1 += btn;} >>> else if (btn == "5") {strng1 += btn;} >>> else if (btn == "6") {strng1 += btn;} >>> else if (btn == "7") {strng1 += btn;} >>> else if (btn == "8") {strng1 += btn;} >>> else if (btn == "9") {strng1 += btn;} >>> >>> could all just be >>> >>> strng1 += btn; >>> >>> because you don't do anything different for the different cases. >>> Copy-paste statement like this should be avoid, because it creates >>> relatively low value redundancy. Try to combine common cases into one >>> block. It's easier to go back and modify later. >>> >>> >>> >> Now that you mention it I see how that would work. However the actual >> program has many non-numeric buttons I don't want in the string - I >> better leave that alone for the present. > > 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? TIA Bill S.