Use App Designer to create a text editor. Create an app that has a large text box as seen in Figure 13.47
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:13| Question number:27.13
All Answers
total answers (1)
classdef TextEditor < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure % UI Figure
LabelSlider matlab.ui.control.Label % Font Size
Slider matlab.ui.control.Slider % [8 32]
Button matlab.ui.control.Button % Bold
Button2 matlab.ui.control.Button % Italic
LabelEditField matlab.ui.control.Label
EditField matlab.ui.control.EditField % hello!
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% Slider value changed function
function FontCallBack(app)
value = app.Slider.Value;
app.EditField.FontSize = value;
end
% Button button pushed function
function BoldButton(app)
app.EditField.FontWeight = 'bold';
end
% Button2 button pushed function
function ItalCallBack(app)
app.EditField.FontAngle = 'italic';
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
setAutoResize(app, app.UIFigure, true)
% Create LabelSlider
app.LabelSlider = uilabel(app.UIFigure);
app.LabelSlider.HorizontalAlignment = 'right';
app.LabelSlider.Position = [62.6875 101 51 15];
app.LabelSlider.Text = 'Font Size';
% Create Slider
app.Slider = uislider(app.UIFigure);
app.Slider.Limits = [8 32];
app.Slider.ValueChangedFcn = ...
createCallbackFcn(app, @FontCallBack);
app.Slider.Position = [134.6875 107 150 3];
app.Slider.Value = 8;
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.ButtonPushedFcn = ...
createCallbackFcn(app, @BoldButton);
app.Button.Position = [333 88 100 22];
app.Button.Text = 'Bold';
% Create Button2
app.Button2 = uibutton(app.UIFigure, 'push');
app.Button2.ButtonPushedFcn = ...
createCallbackFcn(app, @ItalCallBack);
app.Button2.Position = [459 88 100 22];
app.Button2.Text = 'Italic';
% Create LabelEditField
app.LabelEditField = uilabel(app.UIFigure);
app.LabelEditField.HorizontalAlignment = 'right';
app.LabelEditField.Position = [79.03125 379 20 15];
app.LabelEditField.Text = '';
% Create EditField
app.EditField = uieditfield(app.UIFigure, 'text');
app.EditField.Position = [114.03125 178 445 219];
app.EditField.Value = 'hello!';
end
end
methods (Access = public)
% Construct app
function app = TextEditor()
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer