MATLAB 之 App designer 小白学习(二) |
您所在的位置:网站首页 › matlabappdesigner设计案例 › MATLAB 之 App designer 小白学习(二) |
(一) 三 示例学习 2.响应数值输入 (1)主页——新建——APP——响应数值输入
这里将学习 数值输入 响应 图像的相关内容。界面如下,包括左面板:四个数值文本编辑框、一个按钮button、右面板:一个坐标区,坐标区内有网格布局,并相应地对控件的名称、属性进行了修改,这些内容可以自行尝试设计。
我们进入代码视图,学习如何编程实现 界面输入数值 进行 绘图。我按顺次一段一段进行分析。 classdef Mortgage < matlab.apps.AppBase % Properties that correspond to app components properties (Access = public) MortgageCalculatorUIFigure matlab.ui.Figure GridLayout matlab.ui.container.GridLayout LeftPanel matlab.ui.container.Panel LoanAmountEditFieldLabel matlab.ui.control.Label LoanAmountEditField matlab.ui.control.NumericEditField InterestRateEditFieldLabel matlab.ui.control.Label InterestRateEditField matlab.ui.control.NumericEditField LoanPeriodYearsEditFieldLabel matlab.ui.control.Label LoanPeriodYearsEditField matlab.ui.control.NumericEditField MonthlyPaymentButton matlab.ui.control.Button MonthlyPaymentEditField matlab.ui.control.NumericEditField RightPanel matlab.ui.container.Panel PrincipalInterestUIAxes matlab.ui.control.UIAxes end这段代码的作用: 定义APP类,类名称为 Mortgage,控件属性有 :整个界面图布 MortgageCalculatorUIFigure、 网格布局GridLayout、LeftPanel 左面板、数值文本编辑框 及相应的文本框标签LoanAmountEditFieldLabel、LoanAmountEditField、 InterestRateEditFieldLabel、InterestRateEditField , LoanPeriodYearsEditFieldLabel 、LoanPeriodYearsEditField 、 MonthlyPaymentEditField ;按钮 MonthlyPaymentButton 、右面板 RightPanel、坐标区PrincipalInterestUIAxes % Properties that correspond to apps with auto-reflow properties (Access = private) onePanelWidth = 576; end 界面自动重排刷新时的属性定义 onePanelWidth = 576;因为这个界面是分为左面板和右面板两个面板,所以这里只定义了一个面板宽度。意思就是,当你在运行程序的时候,程序界面可以最大化,也可以手动调整大小,为了自适应界面的大小变化,这里固定了一个面板的宽度,无论界面变大变小,这个面板的宽度始终为576. 可以对比一下,小界面为下图
我拉大界面后,可以发现左面板的宽度始终不变,右面板宽度在随界面大小变化。
类比一下,如果是三栏式的,就需要对其中两个进行控制,这样的话界面不容易崩溃报错,如下面黄色部分。 % Properties that correspond to apps with auto-reflow properties (Access = private) onePanelWidth = 576; twoPanelWidth = 768; end但是这两个代码实际意义只是定义面板宽度值,给定这两个面板的宽度是确定值,方便后面对界面调整大小的操作。 我们继续分析接下来的代码 % Callbacks that handle component events methods (Access = private) % Changes arrangement of the app based on UIFigure width function updateAppLayout(app, event) currentFigureWidth = app.MortgageCalculatorUIFigure.Position(3); if(currentFigureWidth |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |