Callback

bind(Object component , String action , PnutsFunction callBackFunction)
unbind(Object component , String action , PnutsFunction callBackFunction)

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.

callBackFunction(EventObject eventObject)

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 a Listener class
  2. Full quarified name of a Listener class + "." + a method name of the class
e.g.
"actionPerformed"
"java.awt.event.ActionListener.actionPerformed"


Back