Well, during custom Listener and Event creation, I cannot figure out followed : I have an Listener interface- ok I have an Event class - ok I have a class which implements methods for registration/removing Listener and notification method - ok.
here is sample (taken from developing Java Beans book) :
An Event class:
A listener interface:
An event source class:
The class wich use source event object:
What bothers me is: What indicate (tell event source object) that a certain event has occurred, and what (how) call the notification method??? We add a listener to Temperature object, but what is that what trigger notification method to be invoked??? [ November 21, 2008: Message edited by: Bear Bibeault ]
Ok. Thank you for posting it here, I didn't know where to place it since there is no JavaBeans forum. I just thought, since in JSP JavaBeans are used frenquently, to put it there. My apologize, again. Does, any know to help me about my question, please?
It's usually the source object that determines whether or not it should raise an event. For instance, if you call a method called setTemperature and the new temperature is different from the existing one: notify away!
I didn't understand you? I'm wondering:"How is defined, what action represent certain event to occurs?" we add listener - object.addSomeListener(this); but how is defined what action represent what event. For instance - if we bound let say this object to certain session (now I go into complex), and add boudListener(this). How our object define that BoundEvent has taken place and it's not ChangeEvent??? What pointing at that matter to defining precise Event happened???
So the question is, how does source event object know, what action has been performed,how it recognize right event, and how call appropriate method of Listener interface? [ November 21, 2008: Message edited by: Slobodan Erakovic ]
Joined: Sep 26, 2008
Well, Am I stupid or what??? Please try to compile the code above. I understand the use of API-s event/listener methods, but I can't make by self any... Can anyone show me the real path logic of making bean? Here is what I DO NOT understand (I'll speak about portion of code I've supplied above) :
we invoke an "addTempChangeListener(this);" on the theTemperature object. This method invoked on this object, only put argumented Listener (in this case -this-) in the Vector of listeners? And that's it! Invoking this methond only that happened! Am I right? I do not see another magic from code. So HOW theTemperature object know that CERTAIN event occurred? WHAT tellS that object that "TempChangedEvent" hass occurred? I don't see anything from code... And HOW we can define (in this example it's in Temperature class) WHAT method of the Listener to be called (suppose that we besides tempChanged() have tempBelowFreezing() and tempAboveBoiling(), methods ). Here we see that after extracting Listeners from Vector each call the same. But what if we have a plenty of methods and different methods should be onvoked (just as MouseListener has five methods).
I hope that this comprehensive question helps, little, in my doubts explanation, in order to anyone of you give an answer to help my understanding... Thanks in advance!