This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes It's about JavaBeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "It Watch "It New topic
Author

It's about JavaBeans

Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

For more information, please read this.

This post has been moved to a more appropriate forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
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?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

No problem. As I'm not familiar with the java.util.Event stuff, I'll leave it for someone more savvy to help you out.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

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!


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
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 ]
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
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!
 
 
subject: It's about JavaBeans