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: Tue, 26 Jun 2012 17:21:48 -0400 Organization: A noiseless patient Spider Lines: 41 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 26 Jun 2012 21:21:48 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="03ebLEozl+tXCe7JS60Feg"; logging-data="14358"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nZLmjBbrdf/nKHH1vWG8s" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: Cancel-Lock: sha1:P9Iihuf+dUsDQl0Zk9IOLzT5G48= Xref: csiph.com comp.lang.java.programmer:15615 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 ... -- Eric Sosman esosman@ieee-dot-org.invalid