Callback

bind(component, action, function)
unbind(component, action, function)

bind() binds a callback function to component. When some event associated with action occur for component the bound function is called with the event object as parameter.

unbind() cancels a callback function to component.

e.g.
import("java.awt.*")
f = frame("title")
f.setLayout(FlowLayout())
f.add(b1 = Button("OK"))
f.show()
bind(b1, "actionPerformed", function (e) println("hello"))

action is one of the followings.

  1. A method name of Listener class
  2. Full quarified name of Listener class + "." + a method name of the class
e.g.
"actionPerformed"
"java.awt.event.ActionListener.actionPerformed"

Method names of java.awt.event.XXXListener class are pre-defined as action.

registerEventListener(listener)

registerEventListener() registers methods of a concrete EventListener class.

e.g.
     registerEventListener(PropertyChangeListener)
     bind (aBean, "propertyChange", func)

Back