This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Using KeyListener on multiple TextFields" Watch "Using KeyListener on multiple TextFields" New topic
Author

Using KeyListener on multiple TextFields

Bryan Hyde
Greenhorn

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,
-Paul
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
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
TEXTFIELDS TO INT