|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
在做《Matlab面向对象编程》第七章取存款的GUI功能时,生成面板的时候没有报错,但是更改存取款数的值并按withdraw和deposit两个按钮没有反应,存款总数一直不变,感觉是callback函数没有起作用,能帮我看看哪里不对嘛?谢谢!
2 h2 {; m. K; r) H& S- balance = 500;%总金额
- input = 0;%存取款数
- hfig = figure('pos',[100,100,300,300]);
- withdrawButton = uicontrol('parent',hfig,'string','withdraw',...
- 'pos',[60 28 60 28]);
- depositButton = uicontrol('parent',hfig,'string','deposit',...
- 'pos',[180 28 60 28]);
- inputBox = uicontrol('parent',hfig,'style','edit','pos',[60 85 180 28],...
- 'string',num2str(input),'Tag','inputBox');
- balanceBox = uicontrol('parent',hfig,'style','edit','pos',[180 142 60 28],...
- 'string',num2str(balance),'Tag','balanceBox');
- textBox = uicontrol('parent',hfig,'style','text','pos',[60 142 60 28],...
- 'string','balance');
- % set(withdrawButton,'callback',@(o,e)withdraw_callback(o,e));
- % set(depositButton,'callback',@(o,e)deposit_callback(o,e));
- withdrawButton.Callback=@withdraw_callback;
- depositButton.Callback=@deposit_callback;" U( Q" U3 j/ X& E: [# Q
8 M" ^# @) A7 V6 Q% r) S, @
: T6 P& ~2 ?' R: _3 n3 H( w* q! A6 K" p& G$ X$ W
- function withdraw_callback(o,e)
- hfig = get(o,'parent');%取款
- inputBox = findobj(hfig,'Tag','inputbox');
- input = str2double(get(inputBox,'string'));
- balanceBox = findobj(hfig,'Tag','balancebox');
- balance = str2double(get(balanceBox,'string'));
- balance = balance - input;
- set(balanceBox,'string',num2str(balance));
- end' u; n4 h7 x4 q& T
8 l ?% L( @& ?1 K/ M1 l- U) k* d! I9 O6 U A7 [
( T9 y/ O. z+ B Y0 i5 N: B- function deposit_callback(o,e)
- hfig = get(o,'parent');%存款
- inputBox = findobj(hfig,'Tag','inputbox');
- input = str2double(get(inputBox,'string'));
- balanceBox = findobj(hfig,'Tag','balancebox');
- balance = str2double(get(balanceBox,'string'));
- balance = balance + input;
- set(balanceBox,'string',num2str(balance));
- end5 U, s6 C4 j Z& S5 v
+ \5 y2 a/ Z5 a- w
- T- f b1 r* S" `8 t! z- G3 c
0 Q* D4 P9 W$ m |
|