An event handler is a verb that is invoked when a Windows event occurs, for example, when a button is pressed. The standard event handling mechanism in J supports three levels of event handler for a given form. If the form name is abc, these are:
abc_handler
(the parent handler) |
| abc_id_class
(e.g. | abc_pressme_button )
| abc_formevent
(e.g. | abc_close )abc_default
(the default handler)
| |
abc
:
abc_handler
is defined, it is executed for every event associated with that form pressme
, then if a verb for that control such as abc_pressme_button
is defined, it is executed;abc_close
, then it is executed
abc_default
is defined, it is executedTypically, most forms will be written using only the second level of event handler. The other two levels allow the programmer to deal easily with special cases.
We can try this out on the form defined above. First define a default handler:
mywin_default=: wdinfo bind 'this is the default'
Click on the form to give it focus, then try pressing a function key. Each time, this new default event handler will be executed. However, when you press on the button, its own event handler is executed.
Now try defining a parent handler:
mywin_handler=: wdinfo bind 'this handles all events'
Once this is defined, it handles all events from the form.
Note that these event handlers are ordinary verbs and can be defined and modified as required. The search for an appropriate event handler takes place at the time the event occurs. For example, delete the parent handler:
erase 'mywin_handler' 1
Now the other event handlers will again be used to respond to the form's events.