欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    2023年实验报告编写一个简易实用的计算器.docx

    • 资源ID:72848225       资源大小:61.65KB        全文页数:13页
    • 资源格式: DOCX        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    2023年实验报告编写一个简易实用的计算器.docx

    实验报告:开课实验室:现代信息交流中心40*开课时间:2023年*月*日一、 实验目的:熟悉Java图形用户界面的开发原理与技术,涉及各种组件和容器技术。学院名称年级、专 业、班学姓号名同组姓名尢课程名称J a va程序设计实验项目名称四、Java图形用户界面开发指导教师尉斌实验类型验证口综合新口设计J创成绩教 师 评 语教师署名:年月 日二、实验内容:编写一个简易实用的计算器。三、源代码清单:package exp3;imp o rt jav a .applet.Applet;import java. awt.Bordcr Lay o ut;i mpor t j av a .awl.Bulton;im p o r t java.a w t . C o 1 or;im p o r t ja v a. a wt.GridL a you t ;imp o rt j a va.awt.Panel;im p o rt j a va.awt. T e xtFie 1 d ;imp o rt jav a . awt.even t . A c t ion E ven t ;im p o r t j ava.awt.eve n t. A ctionListen e r ;c 1 a ss Res u It ext end s P a nel TextF i e Id tf;。i slnitt rue:«if (e.g e tSou r c e() = k ey.divide) «theF i r s t Num = Flo a t.par s eF 1 oa t (re suit .tf.get T e x t();®op e r ali o n = " di v ide"i s I ni t = tr u e;0 I®if (e. get S ou r c e () = k e y.m o d) a theFirstN u m = Float.p a r seF 1 oat (result.tf. g e t T ext();m o p e rati o n = "m o d"islnit = tru e ;)。 if (e.getSou r ce() = k e y.sqrt) st h e FirstNum = F1 o at.p a r s e F 1 oa t (res u It. t f.getTex t ();8”es u 1 t . t f . s e t T e xt( S t r ing.valueO f ( (Math, s qr t (theFirstNum );。 i s In i t = tru e ;01时 f ( e .getSo u r ce() = key. r e cip r o c al) if (r e s u lt.t f .g e tTcxt() .cq u a ls("0 ")res u t Tex t ("Err or");®els e ootheF i r stNum = Floa t . p a rs e F loat (result.tf.g e t T e x t ();gresu 1 t.tf.setText(S t r ing.v a hi e Of( 1 / t heFirstNum);ooojsl n it = tru e ;00 gif ( e . g etS our c e() = k e y.positiv e AndNegative) o i f (resul t . t f. g e tT e x t().e q u a 1 s ("O") ) 00。 o e 1 se i f (resul t . t f . g etText().star t s Wi t h( " - 11 )。 aresul t .tf.se t Text (r e s u 1 t. tf.ge t T e xl ().s u b s t rin g (I);®elseresult. t f. s et T ex t ( 0+ resu 1 t. t f.getText ();a I° « i f (e. getS ou r ce() = key.cq u al) 3t h eS e c o ndNum = Fl o a t .parseFloat(re s u 1 t.t f .gelT e x t ();®if (o p er a t i on.cquals('H') ores u lt.tf.s e t T ext("O");° I对 f (operation, e qua 1 s("a d d")® r e su 1 t. tf.se t T ex t (Strin g .va 1 u e Of(theFirstNum + t h eSec o nd N u m);。 if ( o pe r a t i o n.e q u a I s ("subtra c t")。 «re s u 1 t Text (Stri n g.val u e O f (t h e F irs t N u m - theSecondNum);o if (o p e rat i o n .cq u als(" mu 1 t ip 1 a y")。resu 1 t.tf. s etText (Stri ng.valueO f (theFi r stN u m * theS e c ondN u m);。if (op eration.cquals(ud i vid e " ) 。 if (re s u 1 t. tf. g etTe x t () .equal s (" 0 ")。resu 1 t.tf.s e tTex t ("Error*);« ®«clsewoo r e s u 1 t . tf.s e tTe x t (Stri n gwow . valu e Of (th e F i rstNum / th e S e co n dN u m);®if (o p erati o n. e quals( " mod")if (resul t . t f. g etTex t ().equals(" 0")s u t Text(" E rror");3 o else, g r esuk. t f. s e t T ext(S t r i nggg.v a lueO f ( t h e F i r s t Num %t hcScc o nd N um):b islnit = t rue;«th e Firs t Num = 0:g”heS e con d Num = 0;o operat i on =)®if (e.gct S ourc e () = key. b ac k S p a cc) -if (resu 1 t.tf.ge t T e x t ().e q ualsCO1') 。else , ®if ( r esult.tf. g etText().le ngth () =1 )o <»result.tf.setT ext(" 0 ");。 islnit=true;。» elsegg r esult. t f. s c t T ext( resul t.tf.gctText().s u bstrin g (0,g。ore s ul t ,tf. g etTe x t().lengt h () - 1);g00 |0if (e. get S o u rce() = key. c I e ar E n (er) g r t Tex t ( " 0");i s I n it = tru e ;对 f (e. g e( S o u r ce() = k ey.c a n c el) resul t .tf.setText(" 0 ");®thc F i rstNum = 0;o th e Se c o n dNum = 0;,。 operation = " 0 ;®is I nit = t r u e ;d d J时 f ( e .ge t Sourc e () = key. 1 B r a c ket) 3 f = t h eFir s tN u m; / / 把第一个数赋给 fs = op e ra tion; /把运算符号赋给s4hcF i rs t Num = 0;s t h eSecon d N u m = 0 ;。 opera t io n ="",islnit = irue;回到初始化,再次输入的数值为新的开始,但文本域内容不变010® if ( e .g e t S ource () = key. r B ra c k e t) ooo/ * *。*同"二"触发的结果大体相同,0 */。4 h e Se c on d Num = Float. pars eFloat(result. tf. g e tTe x t();®if (operation.equal s ("") 。 r esu 1 t.tf. s elTex t ("0");° , »if (operat i on.eq u als("add")are suit, t f . setTex t ( S tring. v a 1 ueO f (t h e Fir s t N um + theS e co n d N um);gif (o p er a t i on.equa 1 s ( u s u b t r a ct")r e suit. tf. s e tTe x t(String. v al u e O f (theFirs t Num - t heSecondNum);g if (ope r ati o n. equal s ("m u 11 i pl a y ")。® r esult.tf. s etT ext (String, v al u e Of(the F ir s t Num * t h eSecon d Num);。 if ( o p crat i o n.equals ("divide") i f (re s u 1 l. t f .g e iTex t ().equa 1 s("0")«resul t .tf.sctText(H E r ro r H );。» e Is ere s u 1 t . t f. setT e xt(St r ing.v a 1 u eOf(th e F ir s tNum / t heS e c o ndNum);a3»if ( o pe r ati o n .e q u als("m o d") a«>if (res u It. t f . g etText (). e quals ("O")&resul t .tf.sctTc x tC'Error");g else83 r esuit. t f. s e t T ex t (Strin g.valueOf (theF i rs t Num % t heS e con dNum);T h eFirstNum = f; 把f再重新赋给第一个数o p eration = s;/把s再重新赋给运算符号00)四、运营结果:(给出运营结果贴图)Re s ul t () 4 f = new T e x (Fi e ld("O " ,25);8ad d ( t f);Ic 1 as s Key exte n ds Panel u 11 on b a ckSpac e , cle a rEn t er, canc e 1,1 B ra c k e t ,r B r ackei;B u tto n one, two, t hree» four, five, six, s even, e i g ht, nin e ,But t on a dd, subt r act, mul t ip 1 ay, d ivide;Button s q r t, r e cipr o c al, mo d ;Butto n pos i t i vcAndNcgative, point, c q ua 1 ;水 e y() o selL a yout (new GridL a yo u t (5, 5);backspace = new Button( "backSpa ce.se t For e g round( n ew Color(2 5 5, 0, 0 );» a d d ( b a ckSp a ce);z ero:®clear E nter = new B ut t on("CEu);c 1 ea r Enter.setF o re gr o u nd (new Co 1 o r (255,0, 0 );gadd (cle a rEnter);a nee 1 = n e w But toncan c el. s et F ore g rou nd d( c anc e I);d (new Col o r (255, 0, 0);1 Bracket =new B utton ("(");a d d (IB r a ck e t);r B ra c ket = n ew Butto n (")");®add (rB r a c ke t );。s even = new B u tton("7");3 ad d ( s e ven);weight = new Bu(ton("8");® a dd (eight);®ni n e = new Bu t ton ("9 ");add(nine);adivide = new Butt o n(" / ");® a dd ( d ivide);»sqrt = new But t on("sqrt");«aa d d (sqr t );。 fou r = new Butt o n( " 4");a dd (f o u r);。 five = new But t on("5 ");a dd ( f iv e ):。s i x = new Butt o n ( H 6");9add(six);m u kip 1 ay = n e w Butt o n(" * ");»a d d(mult i play);8mod = n ew But t o n("% ");d d (mo d );。 o ne = new Bu t ton ( u 1");»ad d (on e );"two = new B u t ton ("2 ");。 add(two);“hr e e = n e w B u t ton ("3");»a d d (thre e );u b t r a c t = new B u non®add(subtract);wrecip r oc a 1 = n ew Button( " 1 / x ");g a dd(rcciproca 1 ):az e ro = n e w Button ("0"); »add(zero);w p os i t i veAndN e gativ e = new But t on("+ / ; add (po s i tiv e A n dN e gat i ve);8Poi n t = n ew B u t t on(".");add(poi n t);8ad d = new B utton ("+");。a d d(add);, equal = new Bu t ton ("=");o a dd( e q ual);p u bl i c class Ca 1 c u la t or extend s Ap p let impl e m e n t s ActionLi s tener oRcsu 1 t rcsul t = n e w Rcsul t (); , K e y k e y = new Key();obo o 1 ean isln i(obo o 1 ean isln i(true;S tri ng o peration =f 1 o at t heFirs t Num = 0;« f I o a t the S econdNum = 0;f 1 oa t f = 0;/用于括号计算时的使用Stri n g s ="'; 用于括号计算时的使用pub lie vo i d in i t(), set L ayout(nc w BordcrLay o u t();。 add ( "North", result);«»add(" Center", key);“kcy.ad d . a dd A ction L i stc n cr( t his);akey.div i de.addActionLislener(t h is);®key.e i gh t . a d d ActionL i stener(thi s );ake y .equal.a d d ActionListen e r (this);«ke y .five. a d d Ac t i onLis t ener(thi s );。 k e y .f o u r. ad d ActionLis t enc r (th i s);»key.niod. a d d Ac t io n L i s t e n e r (th is);»ke y . multi p lay. a d dActionL i s t ener(thi s );key. n in e . a ddAc t i o nList e ner(th i s);®kcy.o n e .add Ac t i o nL i sten e r(this);求ey.p o int.addActionLi s t ener (this);key.positiveAn d N e g ative.a d dActi o nL i s t e ner (t h i s );»key.reci p rocaLad d A c tionL i s tener (this);。 key. sev e n.addActionListen e r (this);g k ey.si x .add A c t i o n Lis t e n e r( t his);«key.s q it. addActio n Lis t e n e r (t h i s );kcy.su b tract.addAc t i o n Lis t c n e r(this);e y. t h ree.addAct i o n List e n e r (th is);key. t wo.addAc t ionList e n e r (th i s);key. zer o .ad d A c tionListc n cr( t h i s);key. backSpace.ad d A c tion L is t ener(thi s );okey.c a n c cl.add Ac t io n L i stc n er(th i s);ke y .clearE n t e r .addAc t i on L is t ener(thi s );§ k ey. 1 Brae k et. a d d Ac t io n L i s t en e r(t h is);e y. rBra c k e t. a d dA c ti o n L istene r ( t h is);)apubli c void actio n Perf o rmed(A ctionEv ent e) 。if (e.gctSourcc() = kcy.onc) ® i f ( i s I nit) 。 result.tf.setTe x t ( " 1 ");s Ini t = false;。 o else (o r esul t .tf. s etText (resu 1 t.tf. g etTe x t () +" 1 u );do J»if (e. g e t So u r c e () = key. tw o ) (islnit) a resu 1 t. t f.sctTcx t ("2");3。 »i s In i t = false;。 else e suit. if. s etTe x (result. t f.ge t Te x t () + " 2 ");if ( e .ge t S o urc e () = k e y.t h r c e) i f (isln i t) ,re suit, t f. s e t Texl("3 ");®is I n it = fa 1 se:g。 else oresul t .t f . s e tT e xt(resu 1 t .tf. ge t Tcxt() + " 3 "i f ( e . gets ource() = key.fo u r) if (islni t ) ®resu 1 t.tf. s etText(" 4 ");i s Ini t = false;®r e su 1 t .tf.s e t T e xt( r e su 1 t.tf. g etT e x t () + "4");if (e. g et S o u rce() = k ey. f i v e ) g r e s u lt.tf. se t Te x t("5 ");woisinit = false;or e s u It. tf. sctText(rcs u lt.tf.gctTcxt () + "5");,if,if8g res(e. g etSour c e() = key. s ix) f (is I n it) u 1 t.t f .setText(n 6");doislni t = false;,» else g ores ult.tf. s et T e x t(r e sult.tf. ge(Text() + n6");)°l®if (e. get Sou r ce() = k e y.sev e n) 。i f ( i slnit) ggfes u lt.t f . s eiTex t ("7 ");gisln i t = fal s e ;o el s e 。 o*»re s ult.tf.s e(T e xt(result.tf. g e tT e xt() + " 7 ");),«if (e.getS o urce () = k e y.eight) i f (islnit ) ,。 r esu 1 t.t f .se t T e x t(" 8 ");8时 s In i t = fa 1 s e ;g e 1 se g。r esu lt.tf. setText(r e sult.t f .getTe x t() + " 8 ");° Iwif (e.ge t So u rc e () = key .nine) 。 »if (isln i t) ,。aresult.tf. s e tText(" 9 ");。 g i slnit = fals e ;«。 else a r e su 1 t.tf.set T ext(res u I t . tf.getTe x t () + "9");°gif (e.getS o urce ()k e y .z e ro) 3。 if (res u lt.t f .getText(). equal s (" 0 ")卜§ els e 。 t T e xt( r esu 1 t.tf. get Text() + "0");0 )gif ( e ,g e tS o urc e () = k ey.p o int) 。 oif (re s ult.tf.ge t T e x t(). indexO f= 1) »r es u 1 t . t f. setTe x t(resul t . t f.ge t Tex t () + '*.");i s I n i t = f a Ise;。)0 »if (e.getSo u r c e () = ke y .a d d) 4heF i rstNum = Fl o at.parseF 1 oat(resu 1 t .tf. getText (); wopcr a tio n = "add"a is I nit = true;00 |»i f (c. g e tS o urcc() = kcy.su b tract) gtheFi rstNum = F 1 oat. p arseFlo a t( r esult.tf. g etT ext();。 ooperation = "subtract"§ »is I n i t = tru e ;«if ( e .getSour c e() = k e y, m u 1 t i p I a y) g”h e Fir s t N u m = Float. parscFloa t (r e su 1 t.tf.gctTcx t ();op e ratio n = " m u It i play";

    注意事项

    本文(2023年实验报告编写一个简易实用的计算器.docx)为本站会员(太**)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

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

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

    收起
    展开