发布企业信息

Matlab 图形用户界面设计工具

作者:未知  信息来源:未知  2006-1-26

字体大小:  网友评论  进入论坛  

6 图形用户界面设计工具图 11。2 交互式用户界面设计工具应用示例图 11。1 工序一:窗口初始位置和大小设计【例 11。1-1 】本例演示:界面设计工具 guide 的启动和用户界面窗口初试几何制作。...

11.6 图形用户界面设计工具


图 11.6-1

11.6.2 交互式用户界面设计工具应用示例


图 11.6.2-1 待制作的用户界面


11.6.2.1 工序一:窗口初始位置和大小设计
【例 11.6.2.1-1 】本例演示:界面设计工具 guide 的启动和用户界面窗口初试几何制作。


图 11.6.2.1-1 属性编辑工具界面

11.6.2.2 工序二:对象的几何布局

【例 11.6.2.2-1 】整个用户界面的几何布局:“轴”、控件种类、相对位置及大致尺寸。本例演示:( A )设计工具控制面板上“新对象模块区”的图标的使用;( B )几何布局时不必太多考虑各对象的精细位置和大小。


图 11.6.2.2-1 “第二道工序” 构成控件布局的界面


11.6.2.3 工序三:新建对象的属性设置
【例 11.6.2.3-1 】控件关键属性的设置。本例演示:
(A)属性编辑工具的使用。
(B)当 'Callback' 属性值可用比较简单的 MATLAB 语句表达时,则直接填写;如果语句较多,表达复杂,那么就应采用一个待写的 M 函数名填写。本例中的回调都借助 M 函数文件实现。
(C)当控件上有字符串标识时,应注意文字的对齐方式和注意字体大小,使外观上与对象大小协调。
(D)控件的 'String' 属性字符串的输入格式。在这过程中,可能还要适当调整对象几何尺寸,使字符表现清晰醒目。
(E) 'Units' 采用 'normalized' ,使得所有新建对象随所在图形窗按比例缩放。

11.6.2.4 工序四:用户菜单的制作
用户菜单制作工序比较独立,因此该工序可前可后,也可以与“工序一”相合并。

【例 11.6.2.4-1 】用户菜单的制作。本例演示:菜单编辑工具的使用。在本例中菜单引起的回调都是直接、简单的 MATLAB 语句。


图 11.6.2.4-1 用户菜单编辑器界面


11.6.2.5 工序五:新建图形对象的齐整化
【例 11.6.2.5-1 】控件的齐整化。本例演示:演示“对齐编辑工具”的使用。


图 11.6.2.5-1


11.6.2.6 工序六:回调函数的编写
【例 11.6.2.6-1 】回调函数的编写。本例演示:从处理方便出发编写回调函数。(关于回调函数的详细讨论,请看第 11.5 节的三个算例)

(1)弹出框的回调函数 Mycolormap.m
[Mycolormap.m]
function Mycolormap
popstr={ 'spring' , 'summer' , 'autumn' , 'winter' }; % 弹出框色图矩阵
vpop=get(findobj(gcf, 'Tag' , 'PopupMenu1' ), 'value' ); % 获得选项的位置标识
colormap(eval(popstr{vpop})) % 采用弹出框所选色图

(2)列表框和“ Apply ”按键配合的回调函数 Myapply.m
[Myapply.m]
function Myapply
vlist=get(findobj(gcf, 'Tag' , 'Listbox1' ), 'value' ); % 获得选项位置向量
liststr={ 'grid on' , 'box on' , 'hidden off' , 'axis off' }; % 列表框选项内容
invstr={ 'grid off' , 'box off' , 'hidden on' , 'axis on' }; % 列表框的逆指令
vv=zeros(1,4);vv(vlist)=1;
for k=1:4
if vv(k);eval(liststr{k}); else eval(invstr{k}); end % 按列表选项影响图形
end

(3)动态编辑框的回调函数 Myedit.m
[Myedit.m]
function Myedit
ct=get(findobj(gcf, 'Tag' , 'EditText1' ), 'string' );
eval(ct')


11.6.2.8 为读者提供的配套文件和数据
(1)机器自动生成的主控文件

[Mygui1.m]
function fig = Mygui1()
% This is the machine-generated representation of a Handle Graphics object
% and its children. Note that handle values may change when these objects
% are re-created. This may cause problems with any callbacks written to
% depend on the value of the handle at the time the object was saved.
% This problem is solved by saving the output as a FIG-file.%
% To reopen this object, just type the name of the M-file at the MATLAB
% prompt. The M-file and its associated MAT-file must be on your path.%
% NOTE: certain newer features in MATLAB may not have been saved in this
% M-file due to limitations of this format, which has been superseded by
% FIG-files. Figures which have been annotated using the plot editor tools
% are incompatible with the M-file/MAT-file format, and should be saved as
% FIG-files.

load Mygui1
h0 = figure( 'Units' , 'normalized' , ...
'Color' ,[0.8553876799929505 0.8553876799929505 0.8553876799929505], ...
'Colormap' ,mat0, ...
'FileName' , 'F:\99\m5\Mygui1.m' , ...
'MenuBar' , 'none' , ...
'Name' , 'GUI 工具设计的界面 ' , ...
'PaperPosition' ,[18 180 575.9999999999999 432], ...
'PaperUnits' , 'points' , ...
'Position' ,[0.1484375 0.5291666666666667 0.8 0.35], ...
'Tag' , 'Fig1' , ...
'ToolBar' , 'none' );
h1 = uimenu( 'Parent' ,h0, ...
'Label' , 'Zoom' , ...
'Tag' , 'M_Z' );
h2 = uimenu( 'Parent' ,h1, ...
'Callback' , 'zoom on' , ...
'Label' , 'On' , ...
'Tag' , 'M_Zon' );
h2 = uimenu( 'Parent' ,h1, ...
'Callback' , 'zoom off' , ...
'Label' , 'Off' , ...
'Tag' , 'M_Zoff' );

h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'BackgroundColor' ,[0.7529411764706 0.7529411764706 0.7529411764706], ...
'Callback' , 'Mycolormap' , ...
'ListboxTop' ,0, ...
'Position' ,[0.80859375 0.773809523809524 0.16 0.130952380952381], ...
'String' ,[ 'spring ' ; 'summer ' ; 'autumn ' ; 'winter ' ], ...
'Style' , 'popupmenu' , ...
'Tag' , 'PopupMenu1' , ...
'Value' ,1);
h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'BackgroundColor' ,[1 1 1], ...
'Max' ,2, ...
'Position' ,[0.80859375 0.327380952380952 0.16 0.398809523809524], ...
'String' ,[ 'grid on ' ; 'box on ' ; 'hidden off' ; 'axis off ' ], ...
'Style' , 'listbox' , ...
'Tag' , 'Listbox1' , ...
'Value' ,1);
h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'BackgroundColor' ,[.752941176470588 .752941176470588 .752941176470588], ...
'Callback' , 'Myapply' , ...
'ListboxTop' ,0, ...
'Position' ,[0.80859375 0.12 0.16 0.15], ...
'String' , 'apply' , ...
'Tag' , 'Pushbutton1' );

h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'BackgroundColor' ,[1 1 1], ...
'Callback' , 'Myedit' , ...
'FontName' , 'Times New Roman' , ...
'FontSize' ,10, ...
'HorizontalAlignment' , 'left' , ...
'ListboxTop' ,0, ...
'Max' ,2, ...
'Position' ,[.55078125 .3273809523809524 .232421875 .4523809523809523], ...
'Style' , 'edit' , ...
'Tag' , 'EditText1' );
h1 = axes( 'Parent' ,h0, ...

'CameraUpVector' ,[0 1 0], ...
'CameraUpVectorMode' , 'manual' , ...
'Color' ,[1 1 1], ...
'ColorOrder' ,mat1, ...
'Position' ,[0.05 0.15 0.45 0.65], ...
'Tag' , 'Axes1' , ...

'XColor' ,[0 0 0], ...
'YColor' ,[0 0 0], ...
'ZColor' ,[0 0 0]);
h2 = text( 'Parent' ,h1, ...
'Color' ,[0 0 0], ...
'HandleVisibility' , 'off' , ...
'HorizontalAlignment' , 'center' , ...
'Position' ,[0.4978165938864628 -0.2222222222222221 9.160254037844386], ...
'Tag' , 'Axes1Text4' , ...
'VerticalAlignment' , 'cap' );
set(get(h2, 'Parent' ), 'XLabel' ,h2);
h2 = text( 'Parent' ,h1, ...
'Color' ,[0 0 0], ...
'HandleVisibility' , 'off' , ...
'HorizontalAlignment' , 'center' , ...
'Position' ,[-0.1353711790393013 0.4907407407407408 9.160254037844386], ...
'Rotation' ,90, ...
'Tag' , 'Axes1Text3' , ...
'VerticalAlignment' , 'baseline' );
set(get(h2, 'Parent' ), 'YLabel' ,h2);
h2 = text( 'Parent' ,h1, ...

'Color' ,[0 0 0], ...
'HandleVisibility' , 'off' , ...
'HorizontalAlignment' , 'right' , ...
'Position' ,mat2, ...
'Tag' , 'Axes1Text2' , ...
'Visible' , 'off' );
set(get(h2, 'Parent' ), 'ZLabel' ,h2);
h2 = text( 'Parent' ,h1, ...
'Color' ,[0 0 0], ...
'HandleVisibility' , 'off' , ...
'HorizontalAlignment' , 'center' , ...
'Position' ,[0.4978165938864628 1.064814814814815 9.160254037844386], ...
'Tag' , 'Axes1Text1' , ...

'VerticalAlignment' , 'bottom' );
set(get(h2, 'Parent' ), 'Title' ,h2);
h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'FontName' , ' 隶书 ' , ...
'FontSize' ,13, ...
'HorizontalAlignment' , 'left' , ...
'ListboxTop' ,0, ...
'Position' ,[0.55 0.8 0.2 0.12], ...
'String' , ' 输入绘图指令 ' , ...
'Style' , 'text' , ...
'Tag' , 'StaticText1' );
h1 = uicontrol( 'Parent' ,h0, ...
'Units' , 'normalized' , ...
'BackgroundColor' ,[.752941176470588 .752941176470588 .752941176470588], ...
'Callback' , 'close(gcbf)' , ...
'ListboxTop' ,0, ...
'Position' ,[0.5869921874999999 0.12 0.16 0.15], ...

'String' , 'Close' , ...
'Tag' , 'Pushbutton2' );
if nargout > 0, fig = h0; end

 

(2)配套数据文件
[Myguizzy.m]
function Myguizzy
% 假如 Mygui1.m 所在目录不是 d:\matbook5\mdisk ,那么第 <10> 条就应做相应的改变。
% 一定要保证本函数生成的 Mygui1.mat 与 Mygui1.m 在同一目录。
mat0=jet(64);
mat1=[ 0 0 1.0000
0 0.5000 0
1.0000 0 0
0 0.7500 0.7500
0.7500 0 0.7500
0.7500 0.7500 0
0.2500 0.2500 0.2500];
mat2=[-0.1179 1.3056 9.1603];
save d:\matbook5\mdisk\Mygui1 %<10>

(3)如何利用本节所提供的文件产生图 11.6.2-1 所示的界面
1、把本节提供的 Mygui1.m , Myguizzy.m , Mycolormap.m , Myapply.m , Myedit.m 五个文件放在 MATLAB 的搜索路径上。
2、先运行 Myguizzy.m ,创建数据文件 Mygui1.mat 。
3、运行 Mygui1.m ,就可得到符合要求的界面。

分页:
Google


推荐图文

  • 打败日本,中国台湾极趣世界最小人形机器人将亮相上海机器人展览会

    打败日本,中国台湾极趣

    您知道全球最小的机器人到底有多小呢。这么小的机器人到底有什么样的法宝呢。中国台湾...

  • UG在线切割编程中的应用与技巧

    UG在线切割编程中的应用

    前言 线切割加工通过电极丝与导电工件之间放电腐蚀成型来完成工件加工,由于是非接触加...

  • PROE的曲面设计

    PROE的曲面设计

    唯一要说明的是因为考虑到下身的中间的两条曲线是向里凹而两端是向外凸的,所以我在拐...

广告

机械热点图文

  • 数控车床加工编程典型实例分析2
  • 内螺纹车削加工——数控车床编程实例42
  • 子程序编程方法-数控车床编程实例36
  • 塑料模具动画演示

机械风云人物

Copyright © 2004 51base.com Inc. All rights reserved.

无忧基地 版权所有│粤ICP备06098418号│XHTML | CSS

客服:+86-755-2212 2202 工作时间:周1~5 10点~16点

感谢中国网络提供带宽支持

广告位