File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Event Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Event Handling" Watch "Event Handling" New topic

Event Handling

sanjay gautam
Ranch Hand

Joined: Aug 13, 2000
Posts: 35
hello everybody.
i am facing some problems in event handlig. please help me regarding event generation,listener and and action performed.
how the flow moves from event source to listener and then to corresponding action.

Tushar Kansara
Ranch Hand

Joined: Aug 14, 2000
Posts: 38
At the first place you need to understand that with Java 2 , The event model has changed to Event Delegation model.
The model has got three diff. entities, One The Event, Event Source, Listener.
The Event Source (For Eg. Button) is an object in a awt, which will generate a event. Yes Event in Java are represented in the form of a object.
The Listener has to register with the Event Source in order to receive the notification of an event having occured. The registration can be done using Add.... Method available in the AWT object.
Also note that Java has provided Listener in a form of interface, hence to start with you did create a class and implement the interface in the class. The interface methods will receive the event object as a parameter in the methods.
Of Course there are more sophisticated ways of handling events, Like for eg. Adapters. But for beginners I think you need to start with implementing listener interfaces.
Tushar Kansara
I agree. Here's the link:
subject: Event Handling
jQuery in Action, 3rd edition