Java and Implicit Invocation Java Event Model Illustration

  • Slides: 5
Download presentation
Java and Implicit Invocation -Java Event Model - Illustration

Java and Implicit Invocation -Java Event Model - Illustration

Java Event Model add. Listener Event Source register event listener remove. Listener Event Object

Java Event Model add. Listener Event Source register event listener remove. Listener Event Object fire event. Handler Event Listener

Illustration: Event Object public class XEvent. Object extends Event. Object /* java. util. Event.

Illustration: Event Object public class XEvent. Object extends Event. Object /* java. util. Event. Object */ { public XEvent. Object (Object o) /* o = event source object */ { super(o) /* invoke the constructor of the superclass, Event. Object */ … } } Public interface XListener extends Event. Listener /* java. util. Event. Listener */ { void handle. X (XEvent. Object xeo); } Interface attributes method 1 {} … Class X 1 Listener

Array: fixed size, homogeneous Vector: variable size, heterogeneous Illustration: Event Source public class XAnnouncer

Array: fixed size, homogeneous Vector: variable size, heterogeneous Illustration: Event Source public class XAnnouncer extends Canvas implements Runnable; { private Vector x. Listeners = new Vector; public XAnnouncer () { thread = new Thread(this) thread. start; } public synchronized void add. XListener (x. Listener l) /* only one thread inside this method at once */ {x. Listeners. add. Element(l); } public synchronized void remove. XListener(x. Listener l) {x. Listeners. remove. Element(l); } private void announce. X() {XEvent. Object xeo = new XEvent. Object(this); /* for each x. Listener member. Of x. Listeners, invoke event handler */ x. Listener. handle. X(xeo) } }

Illustration: Event Listener public class X 1 Listener extends Canvas implements XListener, Runnable; {

Illustration: Event Listener public class X 1 Listener extends Canvas implements XListener, Runnable; { public X 1 Listener (XAnnouncer x. Announcer) { x. Announcer. add. XListener(this) } public void handle. X (XEvent. Object xeo) {…} }