function jsq
clear;close all; clc;
%%
%创建 主界面
%创建 主界面
h_main=figure;
set(h_main,'menubar','none','toolbar','none',...
'tag','th_main',...
'unit','normalized','position',[0.4 0.4 0.2 0.2],...
'numbertitle','off',...
'name','简易计算器',...
'defaultuicontrolunit','normalized',...
'defaultuicontrolfontsize',12);
%%
pos=[0.05 0.05 0.2 0.15];
xgap=pos(3);
ygap=pos(4);
h_num0=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1),pos(2),pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','0',...
'tag','tnum0',...
'callback',@fun_num0);
% [...
% 'u=get(handles.rr,''string'');',...
% ]...
% );
% function fun_num0(hObject, eventdata, handles)
% u=get(handles.rr,'string');
h_numzf=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+1*xgap,pos(2)+0*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','+/-',...
'tag','tnumzf',...
'callback',@fun_numzf);
h_numdot=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+2*xgap,pos(2)+0*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','.',...
'tag','tnumdot',...
'callback',@fun_dot);
h_num1=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+0*xgap,pos(2)+1*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','1',...
'tag','tnum1',...
'callback',@fun_num1);
h_num2=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+1*xgap,pos(2)+1*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','2',...
'tag','tnum2',...
'callback',@fun_num2);
h_num3=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+2*xgap,pos(2)+1*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','3',...
'tag','tnum3',...
'callback',@fun_num3);
h_num4=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+0*xgap,pos(2)+2*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','4',...
'tag','tnum4',...
'callback',@fun_num4);
h_num5=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+1*xgap,pos(2)+2*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','5',...
'tag','tnum5',...
'callback',@fun_num5);
h_num6=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+2*xgap,pos(2)+2*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','6',...
'tag','tnum6',...
'callback',@fun_num6);
h_num7=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+0*xgap,pos(2)+3*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','7',...
'tag','tnum7',...
'callback',@fun_num7);
h_num8=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+1*xgap,pos(2)+3*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','8',...
'tag','tnum8',...
'callback',@fun_num8);
h_num9=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+2*xgap,pos(2)+3*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','9',...
'tag','tnum9',...
'callback',@fun_num9);
%%
h_plus=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+3*xgap,pos(2)+0*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','+',...
'tag','tplus',...
'callback',@fun_plus);
h_minus=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+3*xgap,pos(2)+1*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','-',...
'tag','tminus',...
'callback',@fun_minus);
h_multi=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+3*xgap,pos(2)+2*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','*',...
'tag','tmulti',...
'callback',@fun_multi);
h_divi=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+3*xgap,pos(2)+3*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','/',...
'tag','tdivi',...
'callback',@fun_divi);
%%
h_equal=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+3*xgap,pos(2)+4*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','=',...
'tag','tequal',...
'callback',@fun_equal);
h_clearall=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+2*xgap,pos(2)+4*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','C',...
'tag','tclearall',...
'callback',@fun_cc);
h_clearpre=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+1*xgap,pos(2)+4*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','CE',...
'tag','tclearpre',...
'callback','');
h_bspace=uicontrol(h_main,'style','push',...
'unit','normalized','position',[pos(1)+0*xgap,pos(2)+4*ygap,pos(3),pos(4)],...
'BackgroundColor',0.6*[1,1,1],'ForegroundColor','b',...
'String','back',...
'tag','tbspace',...
'callback',@fun_bspace);
%%
h_rr=uicontrol(h_main,'style','edit',...
'unit','normalized','position',[pos(1)+0*xgap,pos(2)+5*ygap,4*pos(3),pos(4)],...
'backgroundcolor',[1 1 1],'foregroundcolor',[1 0 0],...
'horizontalalignment','right',...
'String','',...
'tag','rr',...
'callback','');
%%
%保存数据
handles=guihandles(h_main);
guidata(h_main,handles);
%%
%0-9的回调函数
function fun_num0(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'0');
set(handles.rr,'string',v);
function fun_num1(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'1');
set(handles.rr,'string',v);
function fun_num2(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'2');
set(handles.rr,'string',v);
function fun_num3(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'3');
set(handles.rr,'string',v);
function fun_num4(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'4');
set(handles.rr,'string',v);
function fun_num5(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'5');
set(handles.rr,'string',v);
function fun_num6(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'6');
set(handles.rr,'string',v);
function fun_num7(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'7');
set(handles.rr,'string',v);
function fun_num8(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'8');
set(handles.rr,'string',v);
function fun_num9(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'9');
set(handles.rr,'string',v);
%%
%加减乘除等于的回调函数
function fun_plus(hObject,eventdata,handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'+');
set(handles.rr,'string',v);
function fun_minus(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'-');
set(handles.rr,'string',v);
function fun_multi(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'*');
set(handles.rr,'string',v);
function fun_divi(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'/');
set(handles.rr,'string',v);
function fun_equal(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
if isempty(u)==0
r1=eval(u);
r2=strcat(u,'=',num2str(r1));
set(handles.rr,'string',r2);
end;
%%
%clear、backspace、dot、updown的响应函数
function fun_cc(hObject,eventdata,handles)
handles=guidata(hObject);
set(handles.rr,'string','');
function fun_bspace(hObject,eventdata,handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
if isempty(u)==0
u(end)='';
set(handles.rr,'string',u);
end
function fun_dot(hObject, eventdata, handles)
handles=guidata(hObject);
u=get(handles.rr,'string');
v=strcat(u,'.');
set(handles.rr,'string',v);

