MATLAB Object-Oriented Programming

(Joyce) #1

Events and Listeners Syntax


In this section...
“Components to Implement” on page 11-22
“Name Events” on page 11-22
“Trigger Events” on page 11-23
“Listen to Events” on page 11-23
“Define Event-Specific Data” on page 11-26

Components to Implement


Implementation of events and listeners involves these components:


  • Specification of the name of an event in a handle class — “Name Events” on page 11-
    22.

  • A function or method to trigger the event when the action occurs — “Trigger Events”
    on page 11-23.

  • Listener objects to execute callback functions in response to the triggered event —
    “Listen to Events” on page 11-23.

  • Default or custom event data that the event passes to the callback functions — “Define
    Event-Specific Data” on page 11-26.


Name Events


Define an event by declaring an event name inside an events block. For example, this
class creates an event called ToggledState:

classdef ToggleButton < handle
properties
State = false
end
events
ToggledState
end
end

11 Events — Sending and Responding to Messages

Free download pdf