classdef app1 < matlab.apps.AppBase
properties (Access = public)
UIFigure matlab.ui.Figure
EditFieldLabel matlab.ui.control.Label
EditField matlab.ui.control.EditField
Button matlab.ui.control.Button
end
methods (Access = private)
function createComponents(app)
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
app.EditFieldLabel = uilabel(app.UIFigure);
app.EditFieldLabel.HorizontalAlignment = 'right';
app.EditFieldLabel.Position = [382 282 56 22];
app.EditFieldLabel.Text = 'Edit Field';
app.EditField = uieditfield(app.UIFigure, 'text');
app.EditField.Position = [453 282 100 22];
app.Button = uibutton(app.UIFigure, 'push');
app.Button.Position = [129 282 100 22];
app.Button.Text = 'Reset';
app.Button.ButtonPushedFcn = @app.resetButtonCallback;
app.UIFigure.Visible = 'on';
end
function resetComponents(app)
app.EditFieldLabel = uilabel(app.UIFigure);
app.EditFieldLabel.HorizontalAlignment = 'right';
app.EditFieldLabel.Position = [382 282 56 22];
app.EditFieldLabel.Text = 'Edit Field';
app.EditField = uieditfield(app.UIFigure, 'text');
app.EditField.Position = [453 282 100 22];
app.Button = uibutton(app.UIFigure, 'push');
app.Button.Position = [129 282 100 22];
app.Button.Text = 'Reset';
app.Button.ButtonPushedFcn = @app.resetButtonCallback;
end
function resetButtonCallback(app, ~, ~)
resetComponents(app);
end
end
methods (Access = public)
function app = app1
createComponents(app)
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
function delete(app)
delete(app.UIFigure)
end
end
end
Best Answer