GUI设计的简易计算器附程序
使用Intelji设计mini计算器

使用Intelji设计mini计算器作者:孙丰伟长春信息技术职业学院计算机系软件技术专业2014年11月18日星期二目录1. 实现效果 (1)1.1 运行界面 (1)1.2 错误提示 (1)2. 创建新项目 (2)3. 创建module (4)4. 创建MyMath类 (5)5. 创建MathForm类 (6)5.1 创建GUI Form [MathForm] (6)5.2 界面设计 (7)5.2.1 拖放JLabel到窗口,并修改属性 (7)5.2.2 在Panel中插入新行 (8)5.2.3 拖放JPanel到右下区 (9)5.2.4 在新加入JPanel中按下图拖入控件,并设置相关属性 (9)5.3 实现btnAdd单击事件 (10)5.4 生成主方法,运行程序 (13)5.5 在MathForm.java中添加验证数据的方法 (16)5.6 在btnAdd的单击事件下实现2数相加代码 (17)5.7 实现清除按钮btnClear单击事件 (17)5.8 实现退出按钮btnClose按钮单击事件 (18)5.9 按照加法实现其他运算按钮的单击事件 (18)6. 为程序增加菜单 (18)7. 测试程序 (20)8. 程序源码 (20)8.1 MyMath类 (20)8.2 MathForm类 (21)1. 实现效果1.1 运行界面1.2 错误提示2. 创建新项目3. 创建module注意:必须选择Module SDK。
4. 创建MyMath类package calc;/*** Created by 孙丰伟on 2014/11/18 0018.*/public class MyMath {public static int add(int x,int y){return x+y;}public static int reduce(int x,int y){return x-y;}public static int mul(int x,int y){return x*y;}public static int devide(int x,int y) throws Exception{if(y==0)throw new Exception("除数不能为0 ^_^");return x+y;}}5. 创建MathForm类5.1 创建GUI Form [MathForm]5.2 界面设计5.2.1 拖放JLabel到窗口,并修改属性依次拖入2个JLabel与2个JtextField,属性分别改为:效果如下:5.2.2 在Panel中插入新行鼠标右键下图侧边蓝色区,选择[Insert row after this]菜单插入新行完成效果:5.2.3 拖放JPanel到右下区5.2.4 在新加入JPanel中按下图拖入控件,并设置相关属性相关属性:效果如下:5.3 实现btnAdd单击事件生成代码如下:5.4 生成主方法,运行程序单击鼠标右键,选择[generate]:如果出现下面对话框,则生成主方法失败。
(word完整版)用MATLAB GUI设计简单计算器

摘要基于MATLAB GUI的计算器设计是利用GUIDE创建图形用户界面进行计算器设计。
设计计算器时,主要是考虑到计算器的易用性、功能的常用程度进行计算器界面与功能的设计。
通过调整控件和文本的布局及颜色,使界面简单大方、布局合理,达到界面友好的效果。
计算器设计时主要利用到get和set两个函数进行各个控件属性值的传递和设置。
计算器实现的功能有:数字0~9和小数点的输入显示,平方、开平方和对数的输入显示。
进行四则运算、正弦计算、余弦计算、正切计算和余切计算,可以求阶乘、求百分数和求倒数。
可以进行括号及变量x与变量y的输入,结合坐标轴编辑框和曲线颜色编辑框实现函数的曲线绘制。
最后运行调试,实现基于MATLAB GUI的计算器的设计。
MATLAB GUI介绍MATLAB是美国MathWorks公司出品的商业数学软件,用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境。
MATLAB是matrix和laboratory两个词的组合,意为矩阵工厂,主要面对科学计算、可视化以及交互式程设计的高科技计算环境。
MATLAB是将数值分析、矩阵计算、科学数据可视化以及非线性动态系统的建模和仿真等诸多强大功能集成在一个易于使用的视窗环境中,为科学研究、工程设计以及必须进行有效数值计算的众多科学领域提供了一种全面的解决方案,并在很大程度上摆脱了传统非交互式程序设计语言的编辑模式,特别是所附带的30多种面向不同领域的工具箱支持,使得它在许多科学领域中成为计算机辅助设计和分析、算法研究和应用开发的基本工具和首选平台。
MATLAB的图形用户界面(Graphical User Interface,简称GUI,又称图形用户接口)是指采用图形方式显示的计算机操作用户界面。
与早期计算机使用的命令行界面相比,图形界面对于用户来说在视觉上更易于接受。
MATLAB的图形用户界(GUI)是由光标,窗口,菜单、文字说明等对象构成一个用户界面。
matlab中gui设计计算器原理及设计方案

matlab中gui设计计算器原理及设计方案在MATLAB中设计GUI(图形用户界面)计算器的基本原理和设计方案如下:基本原理:MATLAB的GUI设计基于事件驱动模型。
这意味着当用户与界面交互(例如,点击按钮或输入文本)时,会触发一个或多个事件。
这些事件会调用相应的回调函数,执行相应的操作。
设计方案:1. 启动MATLAB并创建GUI:打开MATLAB。
使用guide命令启动GUI设计器。
2. 添加GUI组件:在GUI设计器中,添加需要的组件,如按钮(push button)、文本框(edit text)、标签(label)等。
3. 设置组件属性:为每个组件设置必要的属性,例如位置、大小、标签文本等。
4. 编写回调函数:双击每个组件,MATLAB会自动生成一个默认的回调函数。
根据需要修改这些函数,以实现所需的功能。
例如,对于按钮,当用户点击它时,可以编写代码来执行相应的计算。
5. 测试GUI:在设计过程中,经常测试GUI以确保其正常工作。
可以使用simulink中的模拟功能,或直接在MATLAB环境中测试。
6. 保存和运行:保存GUI文件。
在MATLAB命令窗口中输入文件名(不包括扩展名),然后按Enter运行GUI。
7. 调试和优化:根据测试结果,调整回调函数和组件属性,优化GUI的行为和外观。
8. 发布:一旦GUI满足所有需求,可以发布它以供其他人使用。
这通常涉及将GUI打包为一个可执行文件或应用程序包。
9. 维护和更新:随着软件的发展,可能需要定期维护和更新GUI。
这可能涉及添加新功能、修复错误或改进性能。
在整个过程中,熟悉MATLAB的GUI设计和编程技巧是非常重要的。
此外,由于GUI设计可能需要反复的测试和调整,因此耐心和细心也是必不可少的。
简易计算器(源码)

简易计算器(源码)以下是一个简易计算器的Python源码,用于执行基本的加、减、乘、除运算:```python#简易计算器def add(x, y):"""相加"""return x + ydef subtract(x, y):"""相减"""return x - ydef multiply(x, y):"""相乘"""return x * ydef divide(x, y):"""相除"""if y != 0:return x / yelse:return "除数不能为零!"print("选择操作:")print("1. 相加")print("2. 相减")print("3. 相乘")print("4. 相除")choice = input("输入你的选择(1/2/3/4): ")num1 = float(input("输入第一个操作数: "))num2 = float(input("输入第二个操作数: "))if choice == '1':print(num1, "+", num2, "=", add(num1, num2))elif choice == '2':print(num1, "-", num2, "=", subtract(num1, num2)) elif choice == '3':print(num1, "*", num2, "=", multiply(num1, num2)) elif choice == '4':print(num1, "/", num2, "=", divide(num1, num2)) else:print("无效的选择")```以上代码中,我们定义了四个函数:`add`、`subtract`、`multiply`和`divide`,分别用于执行相加、相减、相乘和相除的操作。
设计一个图形界面的计算器,完成简单的算术运算-JAVA课程设计

设计一个图形界面的计算器,完成简单的算术运算-JAVA课程设计课程设计论文任务书软件学院学院网络工程专业 2006-2 班一、课程设计论文题目设计一个图形界面的计算器,完成简单的算术运算二、课程设计论文工作自09 年 1 月 5 日起至09年 1 月 9 日止。
三、课程设计论文地点: 信息工程学院中心机房四、课程设计论文内容要求:1.本课程设计的目的(1)使学生巩固和提高Java编程技术(2)培养学生掌握程序设计的基本思路和方法;(3)加强学生研发、调试程序的能力;(4)培养学生分析、解决问题的能力;(5)提高学生的科技论文写作能力。
2.课程设计的任务及要求1)任务:1设计的计算器应用程序可以完成加法、减法、乘法、除法和取余运算2计算器要有小数点、正负号、求倒数、退格和清零功能2)创新要求:计算器附加有开平方根,平方,立方,判断素数,求log的功能3)课程设计论文编写要求(1)课程设计任务及要求(2)设计思路--工作原理、功能规划(3)详细设计---数据分析、算法思路、类设计、功能实现(含程序流程图、主要代码及注释)、界面等。
(4)运行调试与分析讨论---给出运行屏幕截图,分析运行结果,有何改进想法等。
(5)设计体会与小结---设计遇到的问题及解决办法,通过设计学到了哪些新知识,巩固了哪些知识,有哪些提高。
(6)参考文献(必须按标准格式列出,可参考教材后面的参考文献格式)7 报告按规定排版打印,要求装订平整,否则要求返工;8 课设报告的装订顺序如下:封面---任务书---中文摘要---目录----正文---附录代码及相关图片(9)严禁抄袭,如有发现,按不及格处理。
4)答辩与评分标准:(1)考勤:10分;(2)程序检查:30分;(3)答辩回答问题:20分(3)课程设计报告:40分;5)参考文献:[1] 耿祥义.《Java 2 实用教程(第三版)》北京清华大学出版社 2006.8[2] 朱福喜.《Java语言程序设计》.北京清华大学出版社.2005[3] 朱福喜,尹为民,余振坤.《Java语言与面向对象程序设计》.武汉武汉大学出版社.20026)课程设计进度安排内容天数地点构思及收集资料7 图书馆编码与调试 5 实验室撰写论文 3 图书馆、实验室学生签名:09 年 01月 05日课程设计论文评审意见(1)考勤(10分):优( )、良( )、中( )、一般( )、差( );(2)程序检查(30分):优( )、良( )、中( )、一般( )、差( );(3)答辩回答问题(20分):优( )、良( )、中( )、一般( )、差( );(4)设计报告(40分):优( )、良( )、中( )、一般( )、差( );评阅人: 职称: 讲师年月日目录一、课设任务及要求 1二、需求分析 2三、设计思路 3四、详细设计 5五、运行调试与分析讨论9六、设计体会与小结14七、参考文献15附录16中文摘要Java是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台的总称。
嵌入式系统之基于QT的简单计算器

嵌入式系统之基于QT的简单计算器QT是一种跨平台的应用程序开发框架,它提供了一种编写图形用户界面(GUI)程序的简便方法。
在嵌入式系统中,使用QT可以快速开发出各种功能强大、界面友好的应用程序。
对于一个简单计算器来说,主要包括用户界面设计和计算逻辑两部分。
首先,我们需要设计一个界面来展示计算器的按钮和显示结果的区域。
在QT中,可以使用QGridLayout布局管理器来创建按钮布局,同时将其连接到对应的信号槽函数上,以实现按钮的点击响应。
```cpp//main.qmlimport QtQuick 2.12import QtQuick.Window 2.12import QtQuick.Controls 2.12Windowvisible: truewidth: 400height: 600title: "Simple Calculator"RowLayoutspacing: 10GridLayoutid: buttonGridrows: 4columns: 4anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter Buttontext: "7"onClicked: calculator.append("7")}Buttontext: "8"onClicked: calculator.append("8")}// ... more buttons ...Buttontext: "="onClicked: calculator.calculate}// ... more buttons ...}TextFieldid: resultFieldwidth: 200height: 50placeholderText: "0"readOnly: true}}```在这个示例中,我们使用了QT的QML语言来创建用户界面。
matlab-GUI-设计(简易科学计算器)

MATLAB大作业班级:姓名:学号:计算器➢题目本题目通过MATLAB的gui程序设计较为简单,在gui设计中主要用到三种控件,文本编辑框(edit text),静态文本框(Static text),命令按钮(push button)。
然后在通过各个按钮的回调函数,实现简单的计算功能。
➢1、功能介绍(1)具有友好的用户图形界面。
实现十进制数的加、减、乘、除、乘方、开方等简单计算。
(2)具有科学计算函数,包括(反)正弦、(反)余弦、(反)正切、(反)余切、开方、指数等函数运行。
(注:三角函数计算的是弧度而不是角度)。
(3)有清除键,能清除操作。
➢2、功能实现程序由两个部分组成:MATLAB代码(.m文件)和GUI图形(.fig)。
程序使用的流程:直接利用图形界面中的按键键入所需数值、运算符等即可得出结果。
备注:软件版本:MATLAB 2011b首先用MATLAB GUI功能,在绘制一个静态文本框和一个文本编辑框,以及33个命令按钮,调整好各控件大小、颜色,整体布局如图所示:(附录中有相关属性修改介绍)然后通过双击各个按钮来改写其属性,在m文件中编写其回调函数,最后在运行调试。
2.1 各功能界面设计GUI设计界面:注:底部边框用(Panel)工具添加,有两种设计顺序。
(1、先加底部边框,再在底部边框上画功能键。
2、先画功能键,布好局,画底框,全选功能键拖动到底框上。
)2.2 各功能模块实现(可根据需要增减功能键)算法设计:1. 数字键设计:0—9以及小数点函数都一样,只是参数不同:例如:按键‘1’响应:global jjtextString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','1') ;elsetextString =strcat(textString,'1');set(handles.text1,'String',textString)endjj=0;2. 四则运算函数:‘+’功能响应:textString = get(handles.text1,'String');textString =strcat(textString,'+');set(handles.text1,'String',textString)‘-’功能响应:textString = get(handles.text1,'String');textString =strcat(textString,'-');set(handles.text1,'String',textString)‘×’功能响应:textString = get(handles.text1,'String');textString =strcat(textString,'*');set(handles.text1,'String',textString)‘÷’功能响应:textString = get(handles.text1,'String');textString =strcat(textString,'/');set(handles.text1,'String',textString)3. 科学计算函数:例如:‘sin’功能响应:textString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)set(handles.text1,'String','0.') ;elsea = strread(textString, '%f');a=sin(a);set(handles.text1,'String',a)end4. 退格键(DEL):通过取屏幕值,计算出其字符长度,然后取其前N-1项的值来实现退格:global jjtextString = get(handles.text1,'String');if(strcmp(textString,'0.')==1)&(jj==0)set(handles.text1,'String','0.') ;elsess=char(textString);l=length(textString);textString=ss(1:l-1);set(handles.text1,'String',textString)endjj=0;5. 清屏键函数(AC):set(handles.text1,'String','0.') ;2.3 各模块程序添加方法选中一个需添加程序的功能键,右击,View Callbacks,Callback,出现如下图所示界面。
gui开发实例

gui开发实例GUI开发实例引言:Graphical User Interface(图形用户界面)简称GUI,是现代软件开发中常用的一种用户界面设计方式。
通过GUI可以让用户通过图形化的界面和用户交互,方便地操作软件和获取所需信息。
本文将介绍一些常见的GUI开发实例,展示GUI的强大功能和应用领域。
一、音乐播放器音乐播放器是一个常见的GUI应用程序。
通过GUI界面,用户可以方便地浏览音乐库、选择喜爱的音乐、调整音量和播放进度等功能。
界面通常包括音乐列表、播放控制按钮、音量调节器和进度条等元素。
用户可以通过点击按钮或拖动进度条来控制音乐的播放。
二、计算器计算器是另一个常见的GUI应用程序。
通过GUI界面,用户可以进行各种数学计算操作,如加减乘除、求平方根、百分比计算等。
界面通常包括数字键盘、运算符按钮和显示屏等元素。
用户可以通过点击按钮来输入数字和运算符,并在显示屏上看到计算结果。
三、图像编辑器图像编辑器是用于编辑和处理图像的GUI应用程序。
通过GUI界面,用户可以打开图像文件、进行剪裁、调整亮度和对比度、添加滤镜效果等操作。
界面通常包括菜单栏、工具栏、画布和调整面板等元素。
用户可以通过选择工具和调整参数来对图像进行编辑。
四、文本编辑器文本编辑器是用于编辑文本文件的GUI应用程序。
通过GUI界面,用户可以打开、新建、保存和编辑文本文件。
界面通常包括菜单栏、工具栏、文本编辑区和状态栏等元素。
用户可以通过键盘输入文字、选择字体和颜色、进行查找和替换等操作。
五、日历应用日历应用是用于管理时间和日程的GUI应用程序。
通过GUI界面,用户可以查看日期、添加和编辑日程安排、设置提醒等功能。
界面通常包括日期选择器、日程列表和提醒设置等元素。
用户可以通过点击日期和按钮来进行操作,并在界面上看到相应的日程信息。
六、文件管理器文件管理器是用于管理文件和文件夹的GUI应用程序。
通过GUI界面,用户可以浏览目录结构、复制、移动和删除文件、创建和重命名文件夹等操作。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
电子信息工程系实验报告课程名称:MATLAB 应用实验项目名称:GUI 计算器设计实验时间:2012-11-22班级:测控081姓名:学号:810707132实验目的:1.熟悉MATLAB 的菜单设计方法2.熟悉MATLAB 的主要控件使用方法3.熟悉MATLAB 的GUI 设计流程4.运用MATLAB 的GUI 设计一个简单的计算器实验环境:MATLAB7.8实验内容:function varargout =jisuanqi1(varargin)%JISUANQI1M-file for jisuanqi1.fig %JISUANQI1,by itself,creates a new JISUANQI1or raises the existing %singleton*.%%H =JISUANQI1returns the handle to a new JISUANQI1or the handle to %the existing singleton*.%%JISUANQI1('CALLBACK',hObject,eventData,handles,...)calls the local %function named CALLBACK in JISUANQI1.M with the given input arguments.%%JISUANQI1('Property','Value',...)creates a new JISUANQI1or raises the %existing singleton*.Starting from the left,property value pairs are %applied to the GUI before jisuanqi1_OpeningFunction gets called.An %unrecognized property name or invalid value makes property application %stop.All inputs are passed to jisuanqi1_OpeningFcn via varargin.%%*See GUI Options on GUIDE's Tools menu.Choose "GUI allows only one %instance to run (singleton)".%%See also:GUIDE,GUIDATA,GUIHANDLES%Edit the above text to modify the response to help jisuanqi1%Last Modified by GUIDE v2.505-Dec-201022:24:59%Begin initialization code -DO NOT EDIT gui_Singleton =1;成绩:指导教师(签名):'gui_Singleton',gui_Singleton,...'gui_OpeningFcn',@jisuanqi1_OpeningFcn,...'gui_OutputFcn',@jisuanqi1_OutputFcn,...'gui_LayoutFcn',[],...'gui_Callback',[]);if nargin&&ischar(varargin{1})gui_State.gui_Callback=str2func(varargin{1});endif nargout[varargout{1:nargout}]=gui_mainfcn(gui_State,varargin{:}); elsegui_mainfcn(gui_State,varargin{:});end%End initialization code-DO NOT EDIT%---Executes just before jisuanqi1is made visible.function jisuanqi1_OpeningFcn(hObject,eventdata,handles,varargin) %This function has no output args,see OutputFcn.%hObject handle to figure%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%varargin command line arguments to jisuanqi1(see VARARGIN)%以下是本实验初始化部分程序的代码:global c p t c1f;f=0;t=0;p=2;c1=num2str(0);c='0.';set(handles.edit1,'String',c);guidata(hObject,handles);%Choose default command line output for jisuanqi1handles.output=hObject;%Update handles structureguidata(hObject,handles);%UIWAIT makes jisuanqi1wait for user response(see UIRESUME)%uiwait(handles.figure1);%---Outputs from this function are returned to the command line. function varargout=jisuanqi1_OutputFcn(hObject,eventdata,handles)%hObject handle to figure%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%Get default command line output from handles structure varargout{1}=handles.output;%---Executes on button press in pushbutton3.function pushbutton3_Callback(hObject,eventdata,handles)%hObject handle to pushbutton3(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验数字‘8’的程序代码:global t f c;if f=='=';c='0';c=8+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elseif t==0;c=8+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elsec=strcat(c,'8');set(handles.edit1,'String',c);guidata(hObject,handles);t=t+1;end%---Executes on button press in pushbutton4.function pushbutton4_Callback(hObject,eventdata,handles)%hObject handle to pushbutton4(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验数字‘5’的程序代码:global t f c;if f=='=';c='0';c=5+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);elseif t==0;c=5+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elsec=strcat(c,'5');set(handles.edit1,'String',c);guidata(hObject,handles);t=t+1;end%---Executes on button press in pushbutton5.function pushbutton5_Callback(hObject,eventdata,handles)%hObject handle to pushbutton5(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验数字‘2’的程序代码:global t f c;if f=='=';c='0';c=2+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elseif t==0;c=2+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elsec=strcat(c,'2');set(handles.edit1,'String',c);guidata(hObject,handles);t=t+1;end%---Executes on button press in pushbutton6.function pushbutton6_Callback(hObject,eventdata,handles)%hObject handle to pushbutton6(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘+/-’的程序代码:global c t p;c=strcat('-',c);set(handles.edit1,'String',c);guidata(hObject,handles);p=p+1;elsec=strrep(c,'-','');set(handles.edit1,'String',c);guidata(hObject,handles);p=p+1;end%---Executes on button press in pushbutton7.function pushbutton7_Callback(hObject,eventdata,handles)%hObject handle to pushbutton7(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘.’的程序代码:global c t;t=1;c=strcat(c,'.');set(handles.edit1,'String',c);guidata(hObject,handles);%---Executes on button press in pushbutton8.function pushbutton8_Callback(hObject,eventdata,handles)%hObject handle to pushbutton8(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验数字‘3’的程序代码:global t f c;if f=='=';c='0';c=3+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elseif t==0;c=3+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elsec=strcat(c,'3');set(handles.edit1,'String',c);t=t+1;end%---Executes on button press in pushbutton9.function pushbutton9_Callback(hObject,eventdata,handles)%hObject handle to pushbutton9(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验数字‘6’的程序代码:global t f c;if f=='=';c='0';c=6+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elseif t==0;c=6+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elsec=strcat(c,'6');set(handles.edit1,'String',c);guidata(hObject,handles);t=t+1;end%---Executes on button press in pushbutton10.function pushbutton10_Callback(hObject,eventdata,handles)%hObject handle to pushbutton10(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验数字‘9’的程序代码:global t f c;if f=='=';c='0';c=9+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elseif t==0;c=9+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);elsec=strcat(c,'9');set(handles.edit1,'String',c);guidata(hObject,handles);t=t+1;end%---Executes on button press in pushbutton11.function pushbutton11_Callback(hObject,eventdata,handles)%hObject handle to pushbutton11(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘+’的程序代码:global c c1f t;if f=='-';c1=str2num(c1)-str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='+';elseif f=='/'&str2num(c)==0;c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject,handles);c=num2str(0);c1=num2str(0);f='=';elseif f=='/';c1=str2num(c1)/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='+';elseif f=='*';c1=str2num(c)*str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='+';elsec1=str2num(c)+str2num(c1);c1=num2str(c1);guidata(hObject,handles);c=num2str(0);f='+';endt=0;%---Executes on button press in pushbutton12.function pushbutton12_Callback(hObject,eventdata,handles)%hObject handle to pushbutton12(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘-’的程序代码:global c c1f t;if(c1==num2str(0)&f==0)|(c1==num2str(0)&f=='=')c1=str2num(c)-str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='-';elseif f=='+';c1=str2num(c)+str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='-';elseif f=='/'&str2num(c)==0;c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject,handles);c=num2str(0);c1=num2str(0);f='=';elseif f=='/';c1=str2num(c1)/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='-';elseif f=='*';c1=str2num(c)*str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);c=num2str(0);f='-';elsec1=str2num(c1)-str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='-';endt=0;%---Executes on button press in pushbutton13.function pushbutton13_Callback(hObject,eventdata,handles)%hObject handle to pushbutton13(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘*’的程序代码:global c c1f t;if f=='-';c1=str2num(c1)-str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='*';elseif f=='+';c1=str2num(c)+str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='*';elseif f=='/'&str2num(c)==0;c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject,handles);c=num2str(0);c1=num2str(0);f='=';elseif f=='/';c1=str2num(c1)/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);f='*';elseif(c1==num2str(0)&f==0)|(c1==num2str(0)&f=='=');c1=str2num(c)*(str2num(c1)+1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='*';elsec1=str2num(c)*str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='*';endt=0;%---Executes on button press in pushbutton14.function pushbutton14_Callback(hObject,eventdata,handles)%hObject handle to pushbutton14(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘/’的程序代码:global c c1f t;if f=='-';c1=str2num(c1)-str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='/';elseif f=='+';c1=str2num(c)+str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='/';elseif f=='/'&str2num(c)==0;c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject,handles);c=num2str(0);c1=num2str(0);elseif f=='*';c1=str2num(c)*str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='/';elseif(c1==num2str(0)&f==0)|(c1==num2str(0)&f=='=');c1=str2num(c)/(str2num(c1)+1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='/';elsec1=str2num(c1)/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);f='/';endt=0;%---Executes on button press in pushbutton15.function pushbutton15_Callback(hObject,eventdata,handles)%hObject handle to pushbutton15(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验数字‘0’的程序代码:global t f c;if f=='=';c='0';c=0+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elseif t==0;c=0+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elsec=strcat(c,'0');set(handles.edit1,'String',c);t=t+1;end%---Executes on button press in pushbutton16.function pushbutton16_Callback(hObject,eventdata,handles)%hObject handle to pushbutton16(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验数字‘1’的程序代码:global t f c;if f=='=';c='0';c=1+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elseif t==0;c=1+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elsec=strcat(c,'1');set(handles.edit1,'String',c);guidata(hObject,handles);t=t+1;end%---Executes on button press in pushbutton17.function pushbutton17_Callback(hObject,eventdata,handles)%hObject handle to pushbutton17(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验数字‘4’的程序代码:global t f c;if f=='=';c='0';c=4+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elseif t==0;c=4+str2num(c)*10;set(handles.edit1,'String',c);guidata(hObject,handles);elsec=strcat(c,'4');set(handles.edit1,'String',c);guidata(hObject,handles);t=t+1;endfunction edit1_Callback(hObject,eventdata,handles)%hObject handle to edit1(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB%handles structure with handles and user data(see GUIDATA)%Hints:get(hObject,'String')returns contents of edit1as text%str2double(get(hObject,'String'))returns contents of edit1as a double%---Executes during object creation,after setting all properties. function edit1_CreateFcn(hObject,eventdata,handles)%hObject handle to edit1(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB%handles empty-handles not created until after all CreateFcns called%Hint:edit controls usually have a white background on Windows.%See ISPC and COMPUTER.if ispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end%---Executes on button press in pushbutton18.function pushbutton18_Callback(hObject,eventdata,handles)%hObject handle to pushbutton18(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB%handles structure with handles and user data(see GUIDATA)%以下是本实验数字‘7’的程序代码:global t f c;if f=='=';c='0';c=7+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);elseif t==0;c=7+str2num(c)*10;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);elsec=strcat(c,'7');set(handles.edit1,'String',c);guidata(hObject,handles);t=t+1;end%---Executes on button press in pushbutton19.function pushbutton19_Callback(hObject,eventdata,handles)%hObject handle to pushbutton19(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘CE’的程序代码:global c c1f;f=0;c1=num2str(0);c=0;c=num2str(c);set(handles.edit1,'String',c);guidata(hObject,handles);c=num2str(0);t=0;%---Executes on button press in pushbutton20.function pushbutton20_Callback(hObject,eventdata,handles)%hObject handle to pushbutton20(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘=’的程序代码:global c c1f t;if f=='-';c1=str2num(c1)-str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);elseif f=='/'&str2num(c)==0;c2='³ýÊý²»ÄÜΪÁã¡£'guidata(hObject,handles);c=num2str(0);f=0;elseif f=='/';c1=str2num(c1)/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);elseif f=='*';c1=str2num(c)*str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);elsec1=str2num(c)+str2num(c1);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);endt=0;f='=';c=c1;c1=num2str(0);%---Executes on button press in pushbutton21.function pushbutton21_Callback(hObject,eventdata,handles)%hObject handle to pushbutton21(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%---Executes on button press in pushbutton22.function pushbutton22_Callback(hObject,eventdata,handles)%hObject handle to pushbutton22(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘sqrt’的程序代码:global c c1f t;c1=sqrt(str2num(c))c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=c1;c1=num2str(0);t=0;f='=';%---Executes on button press in pushbutton23.function pushbutton23_Callback(hObject,eventdata,handles)%hObject handle to pushbutton23(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘π’的程序代码:global c;c=num2str(pi);set(handles.edit1,'String','¦Ð');guidata(hObject,handles);%---Executes on button press in pushbutton24.function pushbutton24_Callback(hObject,eventdata,handles)%hObject handle to pushbutton24(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘Backspace’的程序代码:global c t;if t==0;c=floor(str2num(c)/10);c=num2str(c);elseif t==2;c=floor(str2num(c));c=num2str(c);c=strcat(c,'.');t=t-1;elseif t==1;c=floor(str2num(c));c=num2str(c);t=t-1;elsec=(floor(str2num(c)*10^(t-1)/10))*10^(-t+2);c=num2str(c);t=t-1;endset(handles.edit1,'String',c);guidata(hObject,handles);%---Executes on button press in pushbutton25.%hObject handle to pushbutton25(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘1/x’的程序代码:global c c1f t;if c==num2str(0)|c1==num2str(0);c2='³ýÊý²»ÄÜΪÁã¡£'set(handles.edit1,'String',c2);guidata(hObject,handles);elsec1=1/str2num(c);c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);endc=num2str(0);c=c1;c1=num2str(0);t=0;f='=';%---Executes on button press in pushbutton26.function pushbutton26_Callback(hObject,eventdata,handles)%hObject handle to pushbutton26(see GCBO)%eventdata reserved-to be defined in a future version of MATLAB %handles structure with handles and user data(see GUIDATA)%以下是本实验‘exp’的程序代码:global c c1f t;c1=exp(str2num(c))c1=num2str(c1);set(handles.edit1,'String',c1);guidata(hObject,handles);c=num2str(0);c=c1;c1=num2str(0);t=0;f='=';实验结果及分析:实验心得:这次实验做的是电脑附件里的计算器,通过该实验我更熟悉掌握了MATLAB中GUI各控件使用方法及应用,最后并利用GUI设计出了计算器,这些让我对GUI页面中的各控件的功能有了进一步的了解。