Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

It's about JavaBeans

 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64702
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64702
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic