This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Using KeyListener on multiple TextFields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using KeyListener on multiple TextFields" Watch "Using KeyListener on multiple TextFields" New topic

Using KeyListener on multiple TextFields

Bryan Hyde

Joined: Jul 14, 2000
Posts: 1
I am trying to use KeyListener on multiple TextFields in one applet. How do I ensure that the applet knows which one generated the event and modifies the other TextFields accordingly?
Paul Caudle
Ranch Hand

Joined: Jun 08, 2000
Posts: 64
Hi Bryan, I hope this is the type of answer you're looking for here:
the KeyEvent class inherits a method called getSource() which will return the object that dispatched the event in the first place. What you could do would be something like:
if(keyEventObject.getSource() == TextFieldObject){
Do whatever you want if the source was that textField;
This will work well if you're handling your event in the same class that you declared your TextFields, which is usually what one would do.
Hope that helps, Bryan,
wood burning stoves
subject: Using KeyListener on multiple TextFields
Similar Threads
Newbie needs help
JSpinner problem
output in a textfield.
Jsp code for retrieving dsts in s text field