MATLAB Object-Oriented Programming

(Joyce) #1

Class Methods for Graphics Callbacks


In this section...
“Referencing the Method” on page 9-52
“Syntax for Method Callbacks” on page 9-52
“Use a Class Method for a Slider Callback” on page 9-53

Referencing the Method


To use an ordinary class method as callback for a graphics object, specify the callback
property as a function handle referencing the method. For example,

uicontrol('Style','slider','Callback',@obj.sliderCallback)

Where your class defines a method called sliderCallback and obj is an instance of
your class.

To use a static method as a callback, specify the callback property as a function handle
that includes the class name that is required to refer to a static method:

uicontrol('Style','slider','Callback',@MyClass.sliderCallback)

Syntax for Method Callbacks


For ordinary methods, use dot notation to pass an instance of the class defining the
callback as the first argument:

@obj.methodName

Define the callback method with the following input arguments:


  • An instance of the defining class as the first argument

  • The event source handle

  • The event data


The function signature would be of this form:

function methodName(obj,src,eventData)
...
end

9 Methods — Defining Class Operations

Free download pdf