Specifications
5 GUI Applications
5-40
Determining Which Button Is Clicked
The callback defines an additional argument, str, that indicates which button,
Prev or Next, was clicked. For the Prev button Callback property (illustrated
above), the
Callback string includes 'Prev' as the last argument. The Next
button
Callback string includes 'Next' as the last argument. The value of str
is used in
case statements to implement each button’s functionality (see the
code listing below).
Paging Forward or Backward
Prev_Next_Callback gets the current index pointer and the addresses from the
handles structure and, depending on which button the user presses, the index
pointer is decremented or incremented and the corresponding address and
phone number are displayed. The final step stores the new value for the index
pointer in the
handles structure and saves the updated structure using
guidata.
Code Listing
function Prev_Next_Callback(hObject, eventdata,handles,str)
% Get the index pointer and the addresses
index = handles.Index;
Addresses = handles.Addresses;
% Depending on whether Prev or Next was clicked change the display
switch str
case 'Prev'
% Decrease the index by one
i = index - 1;
% If the index is less then one then set it equal to the index of the