Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!204.52.135.9.MISMATCH!newsfeed.hal-mli.net!feeder1.hal-mli.net!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: I need a different approach - suggestions please Date: Wed, 27 Jun 2012 14:56:18 -0700 (PDT) Organization: http://groups.google.com Lines: 54 Message-ID: <483152cf-36d3-4dfc-8cb3-8acd6337ff40@googlegroups.com> References: NNTP-Posting-Host: 69.28.149.29 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1340834300 23422 127.0.0.1 (27 Jun 2012 21:58:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 27 Jun 2012 21:58:20 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Received-Bytes: 2902 Xref: csiph.com comp.lang.java.programmer:15681 bilsch wrote: > Eric Sosman wrote: >> bilsch wrote: >>> 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? Do the Backspace and "7" keys perform the same steps in response to the action? If not, why are they calling the same method? If so, huh? -- Lew