All Packages Class Hierarchy This Package Previous Next Index
public class IavaEventListener implements ActionListener, Scriptable { private IavaRuntime runtime=null; private String actionPerformed=null; public IavaEventListener(String actionMethodName) { actionPerformed=actionMethodName; } public void hookUp(IavaRuntime rt) { if (!hookedUp()) // protect from re-assigning runtime=rt; } public boolean hookedUp() { return (runtime!=null); } public void actionPerformed(ActionEvent e) { if (hookedUp()) runtime.callIavaMethod(actionPerformed,new Object[]{e}); } }
public void buttonActionPerformed(ActionEvent e) { ... // do some event handling here }The second implementation pattern uses IavaMethod objects instead of method names:
... Button b=new Button("My Button"); b.addActionListener(new IavaEventListener("buttonActionPerformed")); ...
public class IavaEventListener implements ActionListener, Scriptable {
private IavaRuntime runtime=null; private String methodName=null; private IavaMethod actionPerformed=null;
public IavaEventListener(String actionMethodName) { methodName=actionMethodName; }
public void hookUp(IavaRuntime rt) { if (!hookedUp()) // protect from re-assigning runtime=rt; IavaMethod[] methods=runtime.getDeclaredMethods(); for (int i=0;ipublic boolean hookedUp() { return (runtime!=null && actionPerformed!=null); }
public void actionPerformed(ActionEvent e) { if (hookedUp()) actionPerformed.execute(runtime,new Object[]{e}); }
}
public abstract void hookUp(IavaRuntime rt)
public abstract boolean hookedUp()
All Packages Class Hierarchy This Package Previous Next Index