|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
在做《Matlab面向对象编程》第七章取存款的GUI功能时,生成面板的时候没有报错,但是更改存取款数的值并按withdraw和deposit两个按钮没有反应,存款总数一直不变,感觉是callback函数没有起作用,能帮我看看哪里不对嘛?谢谢!4 N( ^1 N/ x3 k3 n" o
- 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;2 ]6 n$ R4 F! }6 N/ I
3 k8 r1 w7 ?0 }. G7 ~1 `& F
7 |" o+ j/ ]! ]0 R+ F3 f
. l) [. R- v, o7 g8 k2 p* t- 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));
- end5 U" M& X( G$ z x0 O
+ U- U/ o; A3 K6 b+ F+ l4 v g
4 F) Y9 k" v C/ W' A) f0 {' z- d6 W" |' \
- 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));
- end& O( p5 @. P& a9 ] a5 t' B
Q4 w/ C! N; u b& {3 r0 F6 x ` ~( b& r% u" ^2 }" J; X
8 f: h4 L6 t1 O' k C1 M2 Y8 H. Q |
|