• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Event Handling

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Dev Prakash
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is another name given to the event delegation model. That's it
Ajith
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Dev Prakash
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks jane
 
Dev Prakash
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic