您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 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()Appletstart()Appletstop()Appletdestroy()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/htmlAppletAppletAppletpublicAppletContextgetAppletContext()publicStringgetAppletInfo()publicURLgetDocumentBase()publicURLgetCodeBase()publicStringgetParameter(Stringname)publicString[][]getParameterInfo()publicvoidshowStatus(Stringmsg)publicbooleanisActive()AppletHTMLappletAPPLET[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()Exposurepaint(Graphicsg)Appletpaint()paint()paint()AWTpaintrepaint()paint()GraphicsgnewGraphicspaint()paint()update()update()paint()Appletupdate()repaint()repaint()update()repaint()AWTpaint()update()paint()paint()GraphicsFontFontMetricsColorAppletAWTAppletjava.awt.PanelAWTAppletAppletAWTJavaJava“*.au”AppletApplicationAppletAppletpublicvoidplay(URLurl)publicvoidplay(URLurl,Stringname)play(getCodeBase(),“boing.au”);java.applet.AudioClipAppletAudioClippublicvoidplay()publicvoidloop()publicvoidstop()AudioClipnewAppletAppletpublicAudioClipgetAudioClip(URLurl)publicAudioClipgetAudioClip(URLurl,Stringname)AudioClippublicclassSoundPlayextendsApplet{AudioClipsound;publicvoidinit(){try{sound=getAudioClip(getDocumentBase(),spacemusic.au);}catch(Exceptione){}}publicvoidstart(){sound.loop();}public
本文标题:JavaApplet
链接地址:https://www.777doc.com/doc-5892530 .html