Circle

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

计算器TextFieldMIDletProjCalculatorMIDletimportjavax.microedition.lcdui.Choice;importjavax.microedition.lcdui.ChoiceGroup;importjavax.microedition.lcdui.Command;importjavax.microedition.lcdui.Display;importjavax.microedition.lcdui.Form;importjavax.microedition.lcdui.Item;importjavax.microedition.lcdui.ItemStateListener;importjavax.microedition.lcdui.TextField;importjavax.microedition.midlet.MIDlet;importjavax.microedition.midlet.MIDletStateChangeException;publicclassCalculatorMIDletextendsMIDletimplementsItemStateListener{Displaydisplay;Formform;ChoiceGroupsign;TextFieldnumber1TextField;TextFieldnumber2TextField;TextFieldresultTextField;CommandexitCommand;publicCalculatorMIDlet(){//TODOAuto-generatedconstructorstubdisplay=Display.getDisplay(this);form=newForm(计算器);number1TextField=newTextField(第一个数:,,10,TextField.NUMERIC);number2TextField=newTextField(第二个数:,,10,TextField.NUMERIC);resultTextField=newTextField(结果:,,100,TextField.ANY);sign=newChoiceGroup(运算符号,Choice.POPUP,newString[]{+,-,*,/},null);exitCommand=newCommand(退出,Command.EXIT,1);}protectedvoiddestroyApp(booleanarg0)throwsMIDletStateChangeException{//TODOAuto-generatedmethodstub}protectedvoidpauseApp(){//TODOAuto-generatedmethodstub}protectedvoidstartApp()throwsMIDletStateChangeException{//TODOAuto-generatedmethodstubform.append(number1TextField);form.append(number2TextField);form.append(sign);form.append(resultTextField);form.setItemStateListener(this);display.setCurrent(form);form.addCommand(exitCommand);}publicvoiditemStateChanged(Itemi){//TODOAuto-generatedmethodstubdoublef,s,r=0;if(i==sign){switch(sign.getSelectedIndex()){case0:f=Double.parseDouble(number1TextField.getString());s=Double.parseDouble(number2TextField.getString());r=f+s;break;case1:f=Double.parseDouble(number1TextField.getString());s=Double.parseDouble(number2TextField.getString());r=f-s;break;case2:f=Double.parseDouble(number1TextField.getString());s=Double.parseDouble(number2TextField.getString());r=f*s;break;case3:f=Double.parseDouble(number1TextField.getString());s=Double.parseDouble(number2TextField.getString());r=f/s;break;}resultTextField.setString(r+);}}}Circle:publicclassCircleextendsPoint{privatedoubler;publicCircle(){super();r=0;}publicCircle(intx,inty,doubler){super(x,y);this.r=r;}publicdoublegetR(){returnr;}publicvoidsetR(doubler){this.r=r;}publicStringtoString(){//TODOAuto-generatedmethodstubreturnsuper.toString()++r;}publicdoublegetArea(){return3.14*r*r;}}Point:publicclassPoint{privateintx;privateinty;publicPoint(){x=y=0;}publicPoint(intx,inty){this.x=x;this.y=y;}publicintgetX(){returnx;}publicintgetY(){returny;}publicvoidsetX(intx,inty){this.x=x;this.y=y;}publicStringtoString(){returnx++y;}}Cylinder:publicclassCylinderextendsCircle{privatedoubleh;publicCylinder(){super();h=0;}publicCylinder(intx,inty,doubler,doubleh){super(x,y,r);this.h=h;}publicdoublegetH(){returnh;}publicvoidsetH(doubleh){this.h=h;}publicStringtoString(){returnsuper.toString()++h;}publicdoublegetVol(){returngetArea()*h;}}Text:publicclassTest{publicstaticvoidmain(String[]args){Pointpoint=newPoint();System.out.println(point.toString());Pointpoint2=newPoint(3,4);point2.setX(6,0);System.out.println(point2.toString());//测试子类Circlecircle=newCircle(3,4,10);System.out.println(circle.getArea());//测试子类CylinderCylindercylinder=newCylinder(1,1,10,10);System.out.println(cylinder.getVol());}}FirstMIDlet:importjavax.microedition.lcdui.Command;importjavax.microedition.lcdui.CommandListener;importjavax.microedition.lcdui.Display;importjavax.microedition.lcdui.Displayable;importjavax.microedition.lcdui.TextBox;importjavax.microedition.midlet.MIDlet;publicclassFirstMIDletextendsMIDletimplementsCommandListener{privateDisplaydisplay;privateTextBoxtb;privateCommandexitCommand;publicFirstMIDlet(){//TODOAuto-generatedconstructorstubdisplay=Display.getDisplay(this);tb=newTextBox(helloworld!,helloword!,200,0);exitCommand=newCommand(退出,Command.EXIT,1);}publicvoiddestroyApp(booleanarg0){//TODOAuto-generatedmethodstub}publicvoidpauseApp(){//TODOAuto-generatedmethodstub}publicvoidstartApp(){//TODOAuto-generatedmethodstubtb.addCommand(exitCommand);tb.setCommandListener(this);display.setCurrent(tb);}publicvoidcommandAction(Commandc,Displayabled){//TODOAuto-generatedmethodstubif(c==exitCommand){destroyApp(true);notifyDestroyed();}}}itemMIdlet:packagexx;importjava.io.IOException;importjavax.microedition.lcdui.Command;importjavax.microedition.lcdui.Display;importjavax.microedition.lcdui.Form;importjavax.microedition.lcdui.Image;importjavax.microedition.lcdui.ImageItem;importjavax.microedition.lcdui.Item;importjavax.microedition.lcdui.ItemCommandListener;importjavax.microedition.midlet.MIDlet;publicclassxxMIDletextendsMIDletimplementsItemCommandListener{privateDisplaydisplay;privateFormform;privateCommandswitchCommand;ImageItemimageItem;publicxxMIDlet(){display=Display.getDisplay(this);form=newForm(xx登陆);Imageimage=null;try{image=Image.createImage(/1.png);}catch(IOExceptione){e.printStackTrace();}imageItem=newImageItem(图片一,image,Item.L

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功