Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!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 17:30:03 -0700 Organization: A noiseless patient Spider Lines: 55 Message-ID: References: <05a0cbeb-c97e-436b-9daf-e158445b0ac7@googlegroups.com> <4fea2e75$0$292$14726298@news.sunsite.dk> <26dc29ad-d5a8-4d04-91d6-57311ff23c83@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 28 Jun 2012 00:30:01 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="KnXAleWiR2b1CH/F67mjfA"; logging-data="10247"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bLUU/eWgRsD/f71DPhAwx" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 In-Reply-To: <26dc29ad-d5a8-4d04-91d6-57311ff23c83@googlegroups.com> Cancel-Lock: sha1:v+LxzYhTTCykuSrBUeGUd2PD/VU= Xref: csiph.com comp.lang.java.programmer:15687 On 6/26/2012 3:20 PM, Lew wrote: > Arne Vajhøj wrote: >> Lew wrote: >>> markspace wrote: >>>> bilsch wrote: >>>> >>>>> 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. >>>> >>>> >>>> A couple of things. First, even if true, it's better to do something >>>> like this: >>>> >>>> if( btn == "1" || btn == "2" || btn == "3" ... ) >>>> { >>>> // one single case here... >>>> } >>>> >>>> Than it is to use many different if-blocks. Same action for different >>>> inputs, you want to use one code block to implement that action. >>>> >>>> One other important point I'd like to make is that Java strings don't >>>> normally compare with ==. You have to use .equals() instead. Your code >>>> works now because all of the strings are in a single file, but as your >>>> program grows == will no longer work for you. >>>> >>>> This is the normal, and more correct, way to do it: >>>> >>>> if( btn.equals( "1" ) || btn.equals( "2" ) || ... ) >>>> { >>>> strng1 += btn; >>>> } >>> >>> switch (btn) >>> { >>> case "1": >>> case "2": >>> doCaseOneAndTwo(); >>> break; >>> >>> case "3": >>> doCaseThree(); >>> break; >>> >>> default: >>> doAllOtherCases(); >>> break; >>> } >> >> If Java version>= 7. > > Which the OP had better be using. > I am using 1.7.0_04