JavaApplet

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

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

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

资源描述

JavaApplet1Applet2Applet34567AppletAppletJavaAppletJavaAppletJavaAppletApplicationApplicationmain()AppletHTMLHTMLAppletHTMLURLAppletApplicationAppletAppletimportjava.applet.*;publicclassMyAppletextendsApplet{…;}Appletjava.applet.Appletpublic2.1Applet=…./Applet2.BrowserloadsHTMLdocumentAppletclass3.BrowserloadsappletclassesLocation:*;importjava.awt.*;publicclassHelloAppletextendsApplet{publicStrings;publicvoidinit(){s=newString(“HelloWorld!”);}publicvoidpaint(Graphicsg){g.drawString(s,25,25);}}HTMLHEADTITLEHelloWorld/TITLE/HEADappletcode=HelloApplet.classwidth=300height=300/applet/HTMLAppletJava.applet.Appletpublicvoidinit()publicvoiddestroy()publicvoidstart()publicvoidstop()publicvoidpaint(Graphicsg)Appletwebstop()Webstart()destroy()appletinit()start()AppletAppletmain()Appletinit()start()stop()destroy()ƒinit()Appletƒstart()Appletƒstop()Appletƒdestroy()AppletpublicclassSimpleAppletextendsApplet{StringBufferbuffer;publicvoidinit(){buffer=newStringBuffer();addItem(initializing...);}publicvoidstart(){addItem(starting...);}publicvoidstop(){addItem(stopping...);}publicvoiddestroy(){addItem(preparingforunloading(destroy)...);}voidaddItem(StringnewWord){System.out.println(newWord);buffer.append(newWord);repaint();}publicvoidpaint(Graphicsg){g.drawRect(0,0,getSize().width-1,getSize().height-1);g.drawString(buffer.toString(),5,15);}}Demo:AppletAppletJavaAppletAppletHTMLHotJavaNetscapeNavigatorMicrosoftInternetExplorerJavaAppletJavaAppletAppletViewerJavaJavaAppletAppletViewerAppletHTMLAppletViewerjava.awt.FrameAppletViewerHTMLfileorURLappletviewerWebAppletJava•HTMLappletViewerHelloWorld.htmlzHTMLhtmlappletcode=HelloWorld.classwidth=100height=100/applet/htmlAppletAppletAppletƒpublicAppletContextgetAppletContext()ƒpublicStringgetAppletInfo()ƒpublicURLgetDocumentBase()ƒpublicURLgetCodeBase()ƒpublicStringgetParameter(Stringname)ƒpublicString[][]getParameterInfo()ƒpublicvoidshowStatus(Stringmsg)ƒpublicbooleanisActive()AppletƒHTMLappletAPPLET[ARCHIVE=archiveList][CODEBASE=codebaseURL]CODE=appletFile[ALT=alternateText][NAME=appletInstanceName]WIDTH=pixelsHEIGHT=pixels[ALIGN=alignment][VSPACE=pixels][HSPACE=pixels][PARAMNAME=appletParameter1VALUE=value][PARAMNAME=appletParameter2VALUE=value]...[alternateHTML]/APPLETAppletARCHIVE=archiveList[File1,File2,…]AppletCODEBASE=codebaseURLAppletURLAppletgetCodeBase()AppletHTMLgetCodeBase()getDocumentBase()CODE=appletFileApplet.classcodebaseURLNAME=appletInstanceNameAppletAppletgetAppletContext()AppletAppletAppletALT=alternateTextAppletalternateTextWIDTH=pixelsHEIGHT=pixelsAppletALIGN=alignmentAppletHTMLleft,right,top,texttop,middle,absmiddle,baseline,bottom,absbottomVSPACE=pixelsHSPACE=pixelsAppletHTMLAppletJavaappletvspacehspacevspacehspaceheightwidthAppletPARAMNAME=appletParameter1VALUE=valuePARAMAppletAppletgetParameter()PARAMPARAMmain()Stringargs[]AppletgetParameterInfo()PARAMalternateHTMLAppletalternateHTMLHTMLDemo:AppletHTMLHEADTITLEAppletParameterTest/TITLE/HEADappletcode=“AppletPara.classwidth=300height=300paramname=p1value=1111111paramname=p2value=2222222/applet/HTMLpublicclassAppletParaextendsApplet{Strings1,s2;publicvoidinit(){s1=getParameter(p1);s2=getParameter(p2);}publicvoidpaint(Graphicsg){g.drawString(s1,10,10);g.drawString(s2,10,30);}}„Applets1=getParameter(p1);„Appletparamname=p1value=1111111AppletJavaJavaAppletJavaApplicationApplicationpublicclassAppletAppextendsApplet{publicStrings;publicvoidinit(){s=newString(“HelloWorld!”);}publicvoidpaint(Graphicsg){g.drawString(s,25,25);}}publicstaticvoidmain(Stringargs[]){Framef=newFrame(“Applet-App”);AppletAppapp=newAppletApp();f.add(app,“Center”);f.setSize(200,200);f.setVisible(true);f.addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});app.init();app.start();}AppletAWTAWTAppletpaint()update()repaint()AppletAWTpaint()repaint()AWTthreadwaitingupdate()clearareacallpaint()paint()repaint()Exposureƒpaint(Graphicsg)Appletpaint()paint()paint()AWTpaintrepaint()paint()GraphicsgnewGraphicspaint()paint()ƒupdate()update()paint()Appletupdate()ƒrepaint()repaint()update()repaint()AWTpaint()update()paint()paint()GraphicsFontFontMetricsColorAppletAWTAppletjava.awt.PanelAWTAppletAppletAWTJavaJava“*.au”AppletApplicationAppletAppletƒpublicvoidplay(URLurl)ƒpublicvoidplay(URLurl,Stringname)play(getCodeBase(),“boing.au”);java.applet.AudioClipAppletAudioClipƒpublicvoidplay()ƒpublicvoidloop()ƒpublicvoidstop()AudioClipnewAppletAppletƒpublicAudioClipgetAudioClip(URLurl)ƒpublicAudioClipgetAudioClip(URLurl,Stringname)AudioClippublicclassSoundPlayextendsApplet{AudioClipsound;publicvoidinit(){try{sound=getAudioClip(getDocumentBase(),spacemusic.au);}catch(Exceptione){}}publicvoidstart(){sound.loop();}public

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

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

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

×
保存成功