资源描述:
《实验6图形用户界面设计及代码.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验6.图形用户界面设计一、实验目的1.掌握图形对象属性的基本操作;2.掌握菜单及对话框设计、建立控件对象的方法。二、实验环境1.计算机;2.Matlab软件。三、实验说明1.正确操作,认真观察;2.实验学时:2学时;3.学会使用help;4.保存整理实验结果,提交实验报告。四、实验内容1.设计如教材P374图1所示的菜单,并在此基础上增加选项:可以改变曲线的颜色、线型;可以改变窗口背景颜色。2.(选做)采用图形用户界面,从键盘输入参数a、b、n的值,考察参数对极坐标曲线的影响。五、实验程序及结果1.程序:screen=get(0,'ScreenSize');W=
2、screen(3);H=screen(3);figure('Color','w','Position',[0.2*H,0.2*H,0.5*W,0.3*H],...'Name','菜单设计实验','NumberTitle','off','MenuBar','none');hplot=uimenu(gcf,'Label','&Plot');%定义plot菜单项uimenu(hplot,'Label','SineWave','Call',...['t=-pi:pi/20:pi;','h0=plot(t,sin(t));','set(h0,''UIContextMenu'
3、',ht);',...'set(hlr,''Enable'',''on'');','set(hlg,''Enable'',''on'');','set(hlb,''Enable'',''on'');',...'set(hsx,''Enable'',''on'');','set(hss,''Enable'',''on'');']);uimenu(hplot,'Label','CosineWave','Call',...['t=-pi:pi/20:pi;','h0=plot(t,cos(t));','set(h0,''UIContextMenu'',ht);',...
4、'set(hlr,''Enable'',''on'');','set(hlg,''Enable'',''on'');','set(hlb,''Enable'',''on'');',...'set(hsx,''Enable'',''on'');','set(hss,''Enable'',''on'');']);uimenu(hplot,'Label','&Exit','Call','close(gcf)');ho=uimenu(gcf,'Label','&Option');%定义Option菜单项hw=uimenu(ho,'Label','&WindowColor'
5、);uimenu(hw,'Label','&Red','Call','set(gcf,''Color'',''r'');');uimenu(hw,'Label','&Green','Call','set(gcf,''Color'',''g'');');uimenu(hw,'Label','&Blue','Call','set(gcf,''Color'',''b'');');uimenu(hw,'Label','&White','Call','set(gcf,''Color'',''w'');');hl=uimenu(ho,'Label','&LineColor',
6、'Separator','on');hlr=uimenu(hl,'Label','&Red','Call',...'set(h0,''Color'',''r'');','Enable','off');hlg=uimenu(hl,'Label','&Green','Call',...'set(h0,''Color'',''g'');','Enable','off');hlb=uimenu(hl,'Label','&Blue','Call',...'set(h0,''Color'',''b'');','Enable','off');hlw=uimenu(hl,'Lab
7、el','&White','Call',...'set(h0,''Color'',''w'');','Enable','off');ht=uicontextmenu;s=uimenu(ht,'Label','Linestyle');hs=uimenu(ho,'Label','&Linestyle','Separator','on');hsx=uimenu(hs,'Label','&双划线','Call',...'set(h0,''Linestyle'','':'');','Enable','off');hss=uimenu(hs,'Label','&实线','Ca
8、ll',.