Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

listeners  RSS feed

 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was wondering if someone could explain in a few short words what a listener actually does. I notice that every time I add a new actionlistener or keylistener to an object of a class, a new classfile with the addition of the '$' symbol plus the number of listener it is- is placed in the same directory as the original class file. im guessing it is a new thread that sits there waiting for an event and then returns?
thx.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I notice that every time I add a new actionlistener or keylistener to an object of a class, a new classfile with the addition of the '$' symbol plus the number of listener it is- is placed in the same directory as the original class file. im guessing it is a new thread that sits there waiting for an event and then returns?
Nope. I'll guess that you are defining anonymous inner classes for your event handling as your listeners. The JRE has no notion of inner classes. The Java compiler, when it writes the byte code used by the JRE, turns all of your inner classes into "outer" classes. Also, if you haven't provided a name for a class definition, as is the case for anonymous inner classes, then the Java compiler makes up names for them. That's what you are seeing.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering if someone could explain in a few short words what a listener actually does.
Take a look at chapter 57 of Bradley Kjell's Introduction to Computer Science using Java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!