wood burning stoves 2.0*
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
Author

Event Handling

Dev Prakash
Greenhorn

Joined: Oct 09, 2000
Posts: 28
Hi All,
I read few java event handling and got little confused. Here are my questions:
1. Java has two event handling model for 1.0, 1.1, Java2 supports both so How does it decide, which one to choose?
2. What is the need of having components extened and give the method enableEvent() and ProcesXXXXEvents(), and do we generally use these kind of event handling. Does this also make events propagate through all the containment hirarchy.
-Dev Prakash
Viji Bharat
Ranch Hand

Joined: Sep 18, 2000
Posts: 101
Dev Prakash:
For your first question,
Though Java 2 supports both models,
1. The old model will eventualy disappear
2. All the methods supported in the old model are now deprecated.
So, if you have your Java code with methods belonging to both models, it will fail!! Basically, events would be lost or not processed as they should be.
Dev Prakash
Greenhorn

Joined: Oct 09, 2000
Posts: 28
I basically wanna know how events flow internally in the system, In one model it propagate through the containment hirarchy (java1.0)and in one it only innokes the listners(java1.1).
So my Question is: As java2 supports both model, so how it decides for a perticuler event, which model to use?
Thanks
Dev Prakash
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
The new version of Java has adopted the producer-subscriber model instead of event propagation model. There is no question of which event model it uses - there is only one!!
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Dev Prakash
Greenhorn

Joined: Oct 09, 2000
Posts: 28
Hi Ajith,
I never heard of this model "producer-subscriber", I read few books and they all talk about event propagation (java1.0) and event delegation model (java1.1/1.2).
Could you please suggest me any online resource/site/white paper/Artical which explains event handling in detail.
Thanks in Advance..
- Dev Prakash
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
It is another name given to the event delegation model. That's it
Ajith
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Dev,
Here are some links for on-line info on Event Handling:
Sun tutorial on Event Handling
Java AWT Event Delegation Model
Event Generator Idiom:When and How to Make a Java Class Observable article by Bill Venners.
Hope that helps.
------------------
Jane


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Dev Prakash
Greenhorn

Joined: Oct 09, 2000
Posts: 28
Thanks jane
Dev Prakash
Greenhorn

Joined: Oct 09, 2000
Posts: 28
Hi All,
I found the answers of my questions from the SUN's Artical about event handling, I am just posting it here so that all who care can be benifited.
Ajith, My doubt was valid, the New version of Java does not Just support "producer-subscriber" model but support both, here is how:

Compatibility with the old Model
Our intention is to maintain binary compatibility for programs written to the old model for the 1.1 release. However, we strongly recommend new java programs
migrate to the new model. We do not encourage the explicit mixing of the two models within a single Applet. However, we realize that programs which
code to the new model may need/wish to use existing GUI classes which still use the old model and so we have done our best to ensure this works (for
example, the hotjava browser is a java application which will need to be able to load both 1.0 and 1.1 style applets).
The way this works is that the AWT will recognize a component as being either a 1.0-event-model "target" OR a 1.1-event-model "source", but not both. A
component is recognized to be a 1.1-event-model "source" by meeting one of the following conditions:
1.A listener (of any kind) is registered
2.An event type (of any kind) was explicitly enabled by calling enableEvents()
ELSE the component will be treated as a 1.0-event-model "target" and all events will be delivered to the 1.0 handleEvent method as before.
Note that this is an "all or nothing" distinction and that once the AWT determines a component is a particular event model type, ALL events on that component
will be processed in that context. For example, if a TextField object has only a FocusListener registered, then only focus events will be dispatched to the
textfield in the 1.1 mechanism and the old 1.0 handleEvent method will NEVER be called (not even for other event types!). So while it is possible to combine
components which use the different models, it is not possible to get a single component to mix both models.
One key difference between the two models is that the old model would automatically propagate events up the containment hierarchy, while the new model
does NOT propagate events in this way. The way this works for compatibility is that if an event originates on a component which is a 1.0-event-model "target",
then it WILL be propagated up the hierarchy in the 1.0 fashion, regardless of the event model type of its ancestor containers. If an event originates on a
1.1-event-model "source", then that event will NOT propagate up the hierarchy, regardless of the event model type of its ancestor containers.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Yes, Java2 supports the old event propagation model, but it adopts the new event listener model.
Ajith
[This message has been edited by Ajith Kallambella (edited October 18, 2000).]
Vaneet Bhutani
Greenhorn

Joined: Sep 13, 2000
Posts: 18
Alright, now I am confused. My understanding was that prior to Java 1.0, the heirarchal method was standard & after Java 1.1 (including Java 2) support event delegation method. Is that not the case?
Is event delegation model any different from event listener model? Could someone clarify this issue?
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Event Handling
 
Similar Threads
Event Dispatch Thread
Java Swing book
Is multi thread possible
Event Handling in 1.2 1.2 and 1.02
Java Swing book.