I understand the delegation event model in Java, is that it consist of a source that generates an event and send it to one/more listeners... But my problem is; what is the meaning of "generates event", I read books on Java but I see that they don't talk about it. Is that creating an event ( instance ) and throwing it( like exceptions) ? or using flags things.. so I talk about what something that is hided. so let's take an example a button; is a source event ( generates the ActionEvent), ok but how ..?(generates is ... ? I hope the question is clear.. waiting for your comments/answers.
Asked
Active
Viewed 2,116 times
0
-
2You appear to have just picked a host of languages to tag without regard to what your question is about... – wolfPack88 Jul 02 '14 at 16:30
-
1You don't throw events, you listen for them. – rob Jul 02 '14 at 16:58
2 Answers
1
Generating an event is just creating an event object, and calling the listeners. For example, when a button is clicked, it does something like the following:
ActionEvent event = new ActionEvent(this, ...);
for (ActionListener listener : registeredActionListeners) {
listener.actionPerformed(event);
}

JB Nizet
- 678,734
- 91
- 1,224
- 1,255
-
thank you, thats what I needed to know, but I still have a question; is that how It(button) knows that the it was clicked ...? – Jul 02 '14 at 16:44
-
@zarir I recommend you reading [the docs](http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html) and also try using [Google like this](https://www.google.com.mx/search?client=ubuntu&channel=fs&q=jbutton+addactionlistener&ie=utf-8&oe=utf-8&gfe_rd=cr&ei=6Tm0U4ulMIeE8QfUlYGoCg#channel=fs&q=jbutton+actionlistener) so you can get some results. Also try reading [this post](http://stackoverflow.com/questions/284899/how-do-you-add-an-actionlistener-onto-a-jbutton-in-java). Good Luck :) – Frakcool Jul 02 '14 at 16:58
0
I suggest reading about the Observer Pattern to see how a 'Subject' (eg a button) notifies its 'Observers' (eg event listeners)

rob
- 1,286
- 11
- 12