Creating Graphical User Interfaces |
The Contact Phone Number Callback
The Contact Phone # text box displays the phone number of the entry listed in the Contact Name text box. If you type in a new number click one of the push buttons, the callback opens a question dialog that asks you if you want to change the existing number or cancel your change.
Like the Contact Name text box, this callback uses the index pointer (handles.Index
) to update the new number in the address book and to revert to the previously displayed number if the user selects Cancel from the question dialog. Both the current address book and the index pointer are saved in the handles
structure so that this data is available to other callbacks.
If you create a new entry, you must save the MAT-file with the File -> Save menu.
Code Listing
function Contact_Phone_Callback(hObject, eventdata, handles) Current_Phone = get(handles.Contact_Phone,'string');% If either one is empty then return
if isempty(Current_Phone) return end% Get the current list of addresses from the handles structure
Addresses = handles.Addresses; Answer=questdlg('Do you want to change the phone number?', ... 'Change Phone Number', ... 'Yes','Cancel','Yes'); switch Answer case 'Yes'% If no name match was found create a new contact
Addresses(handles.Index).Phone = Current_Phone; handles.Addresses = Addresses; guidata(hObject, handles) return case 'Cancel'% Revert back to the original number
set(handles.Contact_Phone,'String',Addresses(handles.Index).Phone) return end
The Contact Name Callback | Paging Through the Address Book -- Prev/Next |
© 1994-2005 The MathWorks, Inc.