《经典Java程序源代码.docx》由会员分享,可在线阅读,更多相关《经典Java程序源代码.docx(56页珍藏版)》请在优知文库上搜索。
1、经典Java程序源代码1 .加法器(该java源文件的名称是Addenjava)importjava.awu*;importjava.awt.cvcnt.;importjavax.swing.;pub1.icC1.aXSAdderIrnp1.ernen1.sAc1.ion1.is1.enerIJFramCAddcrFramc;JTextFiekITOPrandkJ1.extFieIdTOpr三1.2:J1.abeI1.Add.1.Sum:.!ButtonBA(M,BCIcar;JPaneIJP1.JP2;pub1.icAddert)IA(WcrFran=ncwJFramc(,Ad(krFram
2、c,*);TOpGUHII:OeWJTex1.Fiek1.CQO);TOprand2=newJTcxtFickICQO):1.Add=11cwJ1.abc1.C+);1.Sum=ncwJ1.abc1(=);BAdd二IIeWJBuiton(wAddw);BCIcar=newJBuUonCCkarw);JPI=newJPanc1.();JP2=ncwJPand();BAdd.MdAciion1.iNenerUhisXBCIear.ddAc1.ion1.istener(newAction1.is1.enert)pub1.icvoidactinPerfor11d(ActionEven1.event)
3、TOpramII.SCt1.cxtC0.();TOrax1.2,set1.ext(nO.O):1.Sum.set1ex1.(M=M):I);A(MerFrame.add(JP1.);JP1.addiTOprand1.):JPI.ad1.Add):JPI.aid(TOprand2);JP1.add(1.Sum);AicrFran.add(JP2);JP2.a1.d(BAdd);JPZiKkkBCIear):AddcrFra11c.gctContcntPaneewBordcr1.ay(HitO):A(WcrFran.gctComcntPanc0.akKJP1.Brder1.-ayou1.NORTH
4、);AdderFjme.getCon(eHPane().ad;AddcrFramc.addWindow1.istcncrtnewWindowAdapcr()pub1.icvoidWiIKIoWC1.oSing(WifK1.oWEVen1.event)Systcm.cxit();II);AdderF11n.pack():A(MerFne.seVisib1.e(rue);ACk1.erFnin.se1.Resizab!e(fa1.se):AddcrFrame.setSizc:名称为NotepadJava)2 .小型记事本(该java源文件由两个类构成,importjava.aw(.*;import
5、java.awt.even1.*:importjavax.swing.;importjava.io.*;dnssInynotepadextendsJFrameFi1.ef1.1.c=nukCo1.orCo1.or=Cotormd:myntHepad()ini1.Tex1.Conten1.();initMcnu();initAboutDiaIogO;voidinitTcxtCntcnt()IgetCon(en(PaneO,i.ncwJMenu1.tcm(Sf1.JF*).ncwJMCnIJItCmr保存).ncWJMenU1.temr退出newJMCnUkemC及制),newJMenuhem(剪
6、切),newJMenUhemr粘贴)mcwJMeiwItemC强色.).newJMenukemC关于。);voidinitMcnu()for(inti=OJmenus.1.eng(hi+)nnu.add(nenusi)ir(in1.j=Oijfmenu(i.IengthJ+)(mcnusi).add(op(ionofnwnuij);op(ionofnuij1.addAc(ion1.is(e11ertaction):IIthis.scUMenuBar(mcnu);Action1.istcncraction=ncwAction1.istcncrO添加事件监听pub1.icvoidMtionPe向m
7、ed(Ae1.ionEVeme)Stringname=e.getActionCommand():JMenuItcmMI=(JMenuhem)c.gcSourcc();if(新建”.equa1.s(name)(if(fi1.c!=nu1.1.)openfik.setSe1.ec:if(rctumVa1.=JFi1.eChscr.APPROVEJ)F11ON)f1.1.e=cpenfi1.e.getSe1.ec(edFi1.e():unfo1.d(:e1.seif保存.equak(namc)if(1.e!=nu1.1.)pen1.!e.setSe1.ectedFi1.e(fi1.e):ntretu
8、rnVai=opcnfi!c.showSavcDia1.og(mynotcpad.this):if(rc1.urnVa1.=JFi1.cChooscr.APPROVE_OPTION)(fi1.e=openfi1.e.getSe1.ec(edFi1.e():saving();IIe1.seiff退出1.equaMnamc)mynotepadf=newmyno(epad();intS=JopdonpaneshowConfinnDid1.ogFmiH?M.jHHr.JOp1.ionPane.YES_NO_OPT1.ON);jf(s=jOptionPanc.YES)F1.ON)Systcm.Cxit(
9、O);Ie1.seif(w!7iJJM.equa1.s(name(contcnt.cut();Ie1.seiff复制.equa1.s(name)(con(cnt.coy();e1.sei粘贴”.equak(name)03BJmS=-s,d一QUo-2.3282280一x%o三3No-Xo1.Um.=o-uo3j三v三a-xu三tu三Av一MUUU三M。-=A。一工)-n一Os三WSP三二一-cMoqs.moXos-.Od-SPSTnOqK一UDEnUNIIntW.*+张三%F一XUO-8=2EOX-.三01UXJ三ou!,.2三-三“duouuoPMoq,.JMM三2o。70OOU)(GUi2
10、cngst建,=一OsO一NrpdcBuouvoidunfo1.d()try(FiIcRcaderRCadknCWFiIcRcadcrtfiIc);int1.en=(infi1.e.!engh(:charbuf1.*er=newcharIen;Readf.read(bu1.Ycr.():ReadfdOWXCo1.Nen1.Se1.TeX(newSring(buffer);Icatchckgnound(Co1.or.whi(c);about.getConte11(Pane().add(newJ1.abeK”我的记程序”)H对话框内?about.getCnten1.Pand).add(11ewJ1
11、.a1.1.(,JFwxm):about.gctContcntPane().add(newJ1.abc1.(2007年12月,):about.sctModa1.(1.11*c);设置对话框的湘显示about.setSize(1.00.100);about.sct1.ca(ion(250.170);设置对话框显示位置Icu1.atorJava)pub1.icc1.assNotepadIpub1.icsta1.kvoidmain(Siringargs)入口main函数mynmcpadnotcd=newmynotcpad();eJ.addWindow1.isienertnewWindoWAdaPIerOI);记出本标即设置记事本大小设置记事本显示位竹.ned.setSizd640.320);ncd.show():nocd.set1.ocation(1.50,1.(M);3 .简单计算器(该java源文件的名称是Simp1.eca1.importjava.awt.:importjava.aw(.cvcnt.*;importjavax.swing.;c1.assSimp1.ecaIcuIakHstaticStringPoinyneWSring();staticSi