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:
|(the parent handler)|
|(the default handler)|
When an event occurs, the system searches for an event handler in the order given, and executes the first one it finds. Therefore, for a form
abc_handleris defined, it is executed for every event associated with that form
pressme, then if a verb for that control such as
abc_pressme_buttonis defined, it is executed;
abc_close, then it is executed
abc_defaultis defined, it is executed
Typically, 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.