• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using KeyListener on multiple TextFields

 
Bryan Hyde
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic