[5126] in java-interest
Re: handling event key press in textfield
daemon@ATHENA.MIT.EDU (COLLINS-LEE)
Mon Jan 29 19:39:33 1996
Date: Mon, 29 Jan 96 17:28:56 CST
From: "COLLINS-LEE" <collinsl@norcmail.uchicago.edu>
To: Paul.Bohnenkamp@corp.sun.com, java-interest@java.sun.com
class lacTextField extends TextField
{
int nKeys=0;
CheckBox theCheckBox=null;
lacTextField(String str, int size, CheckBox theBox)
{
super(str, size);
theCheckBox = theBox;
}
setCoorespondingCheckBox( boolean bOn)
{
if (theCheckBox != null)
theCheckBox.setState(bOn);
};
handleEvent(Event evt)
{
switch(evt.id)
{
case Event.KEY_PRESS:
nKeys++;
if (nKeys > 1)
{
setCoorespondingCheckBox(true);
}
default:
return super.handleEvent(evt);
}
} // end method handleEvent
} // end class lacTextField
class TestApplet extends Applet
{
lacTextField[] theTextFields;
CheckBox [] theCheckBoxes;
init()
{
for (int i=0; i!= 10; ++i)
{
theCheckBoxes[i]=new Checkbox();
theTextFields[i]=new lacTextField
(null, 10, theCheckBoxes[i]);
} // end method init()
}// end class TestApplet
**************** THIS IS (Roughly) HOW I DO IT ****************
This way you don't have to worry about which box relates to which field - LET
THE CLASS DOIT
It is always easier to build the functionality INTO the class.
Hope that helped
Lee Collins
(collinsl@norcmail.uchicago.edu)
______________________________ Reply Separator _________________________________
Subject: handling event key press in textfield
Author: Paul.Bohnenkamp@corp.sun.com at INTERNET
Date: 1/25/96 9:18 AM
I've got an array of checkboxes, boxes[i], that correspond to an array of
textfields,fields[i]. If two key presses happen in a textfield I need to set the
state of the corresponding checkbox to true. Can someone explain how I'd use
handleEvent(Event e) to make this happen?
I figured out I have to check (e.target instanceof TextField) but can't figure
out how to tell which field[i] is being operated on?
Here's the e.toString I'm echoing:
java.awt.Event[id=1004,x=116,y=0,target=java.awt.TextField[0,0,238x28,text=,edit
able,selection=0-0]]
thx,
Paul
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com