user3590416
user3590416

Reputation:

event source in Java

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.

Upvotes: 0

Views: 2397

Answers (2)

rob
rob

Reputation: 1286

I suggest reading about the Observer Pattern to see how a 'Subject' (eg a button) notifies its 'Observers' (eg event listeners)

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691715

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);
}

Upvotes: 1

Related Questions