This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one 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


JavaRanch » Java Forums » Java » Beginning Java
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://aspose.com/file-tools
 
subject: Using KeyListener on multiple TextFields