MATLAB Creating Graphical User Interfaces

(ff) #1
...
end

For a fully coded example of a public function, see Plotting App That Opens a Dialog
Box on page 17-16.

(^2) Create a property in the dialog box app to store the main app. Open the dialog box
app into Code View, and create a private property called CallingApp. Select
Property > Private Property in the Editor tab. Then change the property name in
the properties block to CallingApp.
properties (Access = private)
CallingApp % Main app object
end
3 Call the public function from within a callback in the dialog box app. Keeping the
dialog box app open, add a callback function for the OK button.
In this callback, pass the CallingApp property and the user's selections to the
public function. Then call the delete function to close the dialog box.
function ButtonPushed(app,event)
% Call main app's public function
updateplot(app.CallingApp,app.EditField.Value,app.DropDown.Value);
% Delete the dialog box
delete(app)
end
Manage Windows When They Close
Both apps must perform certain tasks when the user closes them. Before the dialog box
closes, it must re-enable the Options button in the main app. Before the main app closes,
it must ensure that the dialog box app also closes.
1 Open the dialog box app into Code View, right-click the app.UIFigure object in the
Component Browser, and select Callbacks > Add CloseRequestFcn callback.
Then add code that re-enables the button in the main app and closes the dialog box
app.
function DialogAppCloseRequest(app,event)
% Enable the Plot Options button in main app
app.CallingApp.OptionsButton.Enable = 'on';
Creating Multiwindow Apps in App Designer

Free download pdf