Article View: borland.public.jbuilder.java.language
Article #15524Re: Need Help
From: Rich Wilkman
Date: Thu, 03 Jun 1999 00:00
Date: Thu, 03 Jun 1999 00:00
58 lines
2377 bytes
2377 bytes
Ed:
Outside of a handful of awt components, no component has a default
name. You must explicitly set the name (and there is nothing that
prevents you from naming all of your widgets "fred"). If you want to
use getName(), make sure you use setName() as well.
-Rich
Ed wrote:
>
> I have an applet with 5 checkboxes, and a text field. I wanted the
> textbox to show which checkbox was clicked. I first tried to get this
> the long way:
>
> if ( e.getItemSelectable() == checkbox1 ) {
> text1.setText( "Check Box 1 Clicked" );
> ...
> etc.
>
> I then realized that I should be able to create a checkbox to hold the
> currently selected item:
>
> public void itemStateChanged( ItemEvent e ) {
> Checkbox hold;
>
> hold = (Checkbox) e.getItemSelectable();
> text1.setText( hold.getLabel() + " was clicked." );
> }
>
> This code worked fine. I am having a problem when I ask for the
> components name:
> hold = (Checkbox) e.getItemSelectable();
> text1.setText( hold.getName() + " was clicked." );
>
> This returns checkbox0 for the first checkbox clicked (doesn't matter
> which one is chosen first) and then checkbox1 for the next, and so on.
>
> My question is (finally) why doesn't the getName() give me the
> "correct" answer. The getLabel() works correctly.
>
> Thanks
> Ed
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Rich Wilkman
Senior Quality Assurance Engineer
Borland JBuilder Team
If you see something that looks like an opinion up there,
it's mine and mine alone.
Mail sent to me from the newsgroups won't bounce but will
be ignored. If I have time, I'll respond, but you have
a better chance if you confine your posts to the newsgroups
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Technical Details
Message-ID:
<37570814.82FF3F7F@inprise.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3757b77d.14818678@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,38e75a1cc4399d93 X-Google-Attributes: gidf74b3,public From: Rich Wilkman <rwilkman@inprise.com> Subject: Re: Need Help Date: 1999/06/03 Message-ID: <37570814.82FF3F7F@inprise.com> X-Deja-AN: 485445865 Content-Transfer-Encoding: 7bit References: <3757b77d.14818678@forums.borland.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language