🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #7747

Re: Handling events issue

#7747
From: Nabin Thomas
Date: Tue, 22 May 2001 03:17
46 lines
2433 bytes
Instead of using anonymous inner classes for event handling, Use named classes.
Create an instance for this class as eventhandler and keep the variable
somewhere such that it is accessible from inside the Frame.
Now for each textbox set this as event handler for keytyped events
As

textbox.addKeyListener(myEventHandler);

Now to access the textboxes as arrays you can just declare them as

TextBox txtBoxes[]=new TextBox[10]; //create references
for(i=0;i<10;i++)
    txtBoxes[i]=new TextBox(); //create the text box

To identify from where the event occured, you can use the getComponent()
Method of KeyEvent.


KK wrote:

> Dear all:
>
> I find it difficult in handling events when so many events have the same
> codes. For example, if I write a form with a hundred
> text boxes and I want to check if any of them has been modified in order to
> enable the "Save" button, I have to write same codes in the of "_keyTyped"
> events of these hundred text boxes. In VB, we can an indexed text boxes from
> 0 to 99 and write a line of code for these text boxes. I don't think Java
> has the same feature. But anyway, is there a simplier way to do so? Thanks
> for your help.
>
> Ken

--
        ***********************************
***************************************************

Nabin Thomas

nabinthomas@hotmail.com

Feel free to contact me thru e-mail or MSN Mssenger
if required but DONOT SPAM

***************************************************
 ***********************************
Technical Details
Message-ID: <3B09DA46.530B9EEF@hotmail.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!193.174.75.178!news-fra1.dfn.de!news-lei1.dfn.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews
References: <3b087273_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,6b38d73c5e82a869
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-05-21 22:38:39 PST
Message-ID: <3B09DA46.530B9EEF@hotmail.com>
Date: Tue, 22 May 2001 08:47:26 +0530
From: Nabin Thomas <nabinthomas@hotmail.com>
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language
Subject: Re: Handling events issue
References: <3b087273_1@dnews>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 202.9.167.151
X-Trace: dnews 990508745 202.9.167.151 (21 May 2001 22:19:05 -0700)
Lines: 50
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!193.174.75.178!news-fra1.dfn.de!news-lei1.dfn.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews