1 / 5

Java and Implicit Invocation

Java and Implicit Invocation. Java Event Model Illustration. Java Event Model. addListener. Event Source. register event listener. removeListener. Event Object. Event Listener. fire event. eventHandler. Illustration: Event Object.

eitan
Download Presentation

Java and Implicit Invocation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java and Implicit Invocation Java Event Model Illustration

  2. Java Event Model addListener Event Source register event listener removeListener Event Object Event Listener fire event eventHandler

  3. Illustration: Event Object public class XEventObject extends EventObject /* java.util.EventObject */ { public XEventObject (Object o) /* o = event source object */ { super(o) /* invoke the constructor of the superclass, EventObject */ … } } Public interface XListener extends EventListener /* java.util.EventListener */ { void handleX (XEventObject xeo); }

  4. Illustration: Event Source public class XAnnouncer extends Canvas implements Runnable; { private Vector xListeners = new Vector; public XAnnouncer () { thread = new Thread(this) thread.start; } public synchronized void addXListener (xListener l) /* only one thread inside this method at once */ {xListeners.addElement(l);} public synchronized void removeXListener(xListener l) {xListeners.removeElement(l);} private void announceX() {XEventObject xeo = new XEventObject(this); /* for each xListener memberOf xListeners, invoke event handler */ xListener.handleX(xeo) } }

  5. Illustration: Event Listener public class X1Listener extends Canvas implements XListener, Runnable; { public X1Listener (XAnnouncer xAnnouncer) { xAnnouncer.addXListener(this) } public void handleX (XEventObject xeo) { … } }

More Related