简单计算器的GUI设计.doc

上传人:豆**** 文档编号:28506529 上传时间:2022-07-28 格式:DOC 页数:4 大小:28KB
返回 下载 相关 举报
简单计算器的GUI设计.doc_第1页
第1页 / 共4页
简单计算器的GUI设计.doc_第2页
第2页 / 共4页
点击查看更多>>
资源描述

《简单计算器的GUI设计.doc》由会员分享,可在线阅读,更多相关《简单计算器的GUI设计.doc(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精品文档,仅供学习与交流,如有侵权请联系网站删除 简单计算器的GUI设计运行结果:源代码:function varargout = jisuanji(varargin)gui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, jisuanji_OpeningFcn, . gui_OutputFcn, jisuanji_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & i

2、schar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);endfunction jisuanji_OpeningFcn(hObject, eventdata, handles, varargin)handles.output = hObject;guidata(hObject, handles);function

3、varargout = jisuanji_OutputFcn(hObject, eventdata, handles) varargout1 = handles.output;% - Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)%乘号“”键的回调函数;signs=get(handles.edit1,string);set(handles.edit1,string,strcat(signs,*);% - Executes on button pr

4、ess in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)%除号“”键的回调函数;signs=get(handles.edit1,string);set(handles.edit1,string,strcat(signs,/);% - Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% - Executes on button press in push

5、button4.function pushbutton4_Callback(hObject, eventdata, handles)%加号“+”键的回调函数;signs=get(handles.edit1,string);set(handles.edit1,string,strcat(signs,+);% - Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)%减号“”键的回调函数;signs=get(handles.edit1,string);se

6、t(handles.edit1,string,strcat(signs,-);% - Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)%数字键7的回调函数:numbers=get(handles.edit1,string);set(handles.edit1,string,strcat(numbers,7);% - Executes on button press in pushbutton8.function pushbutton8_Callba

7、ck(hObject, eventdata, handles)%数字键4的回调函数:numbers=get(handles.edit1,string);set(handles.edit1,string,strcat(numbers,4);% - Executes on button press in pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)%数字键1的回调函数:numbers=get(handles.edit1,string);set(handles.edit1,string,strcat(nu

8、mbers,1);% - Executes on button press in pushbutton10.function pushbutton10_Callback(hObject, eventdata, handles)%数字键0的回调函数: %get函数获取输入文本框edit1的string属性,赋值给numbers,数值类型为char;numbers=get(handles.edit1,string); %字符串合并函数strcat()将按键0与numbers的值合并,将合并后的字符串返回到输入文本框edit1的string属性;set(handles.edit1,string,st

9、rcat(numbers,0);%同理编写其余数字键、小数点键、小括号键、运算符号键;% - Executes on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)%数字键8的回调函数:numbers=get(handles.edit1,string);set(handles.edit1,string,strcat(numbers,8);% - Executes on button press in pushbutton12.function pushbutton1

10、2_Callback(hObject, eventdata, handles)%数字键5的回调函数:numbers=get(handles.edit1,string);set(handles.edit1,string,strcat(numbers,5);% - Executes on button press in pushbutton13.function pushbutton13_Callback(hObject, eventdata, handles)%数字键2的回调函数:numbers=get(handles.edit1,string);set(handles.edit1,string

11、,strcat(numbers,2);% - Executes on button press in pushbutton14.function pushbutton14_Callback(hObject, eventdata, handles)%左括号“(”键的回调函数;signs=get(handles.edit1,string);set(handles.edit1,string,strcat(signs,();% - Executes on button press in pushbutton15.function pushbutton15_Callback(hObject, event

12、data, handles)%右括号“)”键的回调函数;signs=get(handles.edit1,string);set(handles.edit1,string,strcat(signs,);% - Executes on button press in pushbutton16.function pushbutton16_Callback(hObject, eventdata, handles)%数字键9的回调函数:numbers=get(handles.edit1,string);set(handles.edit1,string,strcat(numbers,9);% - Exec

13、utes on button press in pushbutton17.function pushbutton17_Callback(hObject, eventdata, handles)%数字键6的回调函数:numbers=get(handles.edit1,string);set(handles.edit1,string,strcat(numbers,6);% - Executes on button press in pushbutton18.function pushbutton18_Callback(hObject, eventdata, handles)%数字键3的回调函数:n

14、umbers=get(handles.edit1,string);set(handles.edit1,string,strcat(numbers,3);% - Executes on button press in pushbutton19.function pushbutton19_Callback(hObject, eventdata, handles)%小数点的回调函数;point=get(handles.edit1,string);set(handles.edit1,string,strcat(point,.);% - Executes on button press in pushb

15、utton20.function pushbutton20_Callback(hObject, eventdata, handles)%等号“=”号键的回调函数;%get函数获取输入文本框edit1的string属性,并赋值与x;x=get(handles.edit1,string);%利用执行字符串命令eval()计算用户输入的表达式,得到的结果为char型;y1=eval(x);%利用字符串输出格式控制函数sprintf()将字符型常量精确到小数点后十位;y=sprintf(%.10f,y1);%利用属性设置函数set()将字符型结果返回到输出文本框edit2的string属性;set(h

16、andles.edit2,string,y);% - Executes on button press in pushbutton21.function pushbutton21_Callback(hObject, eventdata, handles)%Delete键的回调函数;%get()函数获取当前输入文本框的string属性,并赋值与s1;s1=get(handles.edit1,string);%length(s1)函数获取s1字符串的长度,并利用s1(1:length(s1)-1)获取s1的第一个到第(length(s1)-1)个字符串,已达到删除前一个字符的目的;s2=s1(1:

17、(length(s1)-1);%利用属性设置函数set()将字符型结果返回到输入文本框edit1的string属性;set(handles.edit1,string,s2);% - Executes on button press in pushbutton22.function pushbutton22_Callback(hObject, eventdata, handles)%CLC键的回调函数;%清空输入文本框edit1的string属性;set(handles.edit1,String,);%清空输出文本框edit2的string属性;set(handles.edit2,String,

18、0);% - Executes on button press in pushbutton23.function pushbutton23_Callback(hObject, eventdata, handles)%Exit键的回调函数;close;function edit1_Callback(hObject, eventdata, handles)% - Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)if i

19、spc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);endfunction edit2_Callback(hObject, eventdata, handles)% - Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end【精品文档】第 4 页

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 小学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁