您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 46Java第07章--1(JavaApplet)
JavaJavapenggang@mail.hust.edu.cnAppletApplet123456781appletapplicationapplicationmain()appletHTMLHTMLappletHTMLAPPLETOBJECTURLUniversalResourceLocatorHTMLURLappletapplicationJavaappletAWTjava.applet.AppletSwingjavax.swing.JAppletJAppletApplet2.1=…./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/HTMLHelloApplet.javaAppletJApplet•AppletAWTpanelappletjava.appletpublicclassAppletextendsPanel{publicApplet()throwsHeadlessException{...}publicvoidinit(){...}//appletpublicvoidstart(){...}//appletpublicvoidstop(){...}//appletpublicvoiddestroy(){...}/*applet*/...}javax.swingJAppletAppletAppletJApplet•–Appletappletadd()appletButtonbutton=newButton();applet.add(button);JAppletappletJAppletAppletrootPanelayeredPanecontentPaneglassPane4JAppletJButtonbutton=newJButton();applet.getContentPane().add(button);AppletJApplet•–AppletFlowLayout–JAppletBorderLayoutBorderLayout.CENTER•JAppletJMenuBarApplet2——appletappletJava.applet.Appletpublicvoidinit()publicvoiddestroy()publicvoidstart()publicvoidstop()publicvoidpaint(Graphicsg)appletWebstop()Webstart()stop()destroy()appletinit()start()javax.swingJAppletApplet2——appletappletAppletpublicAppletContextgetAppletContext()publicStringgetAppletInfo()publicURLgetDocumentBase()publicURLgetCodeBase()publicStringgetParameter(Stringname)publicString[][]getParameterInfo()publicvoidshowStatus(Stringmsg)publicbooleanisActive()2——applet•6.5P437ProductJApplet.java•–applet4–JAppletContainerContainerpaint()JAppletSwingJComponentpaintComponent()JAppletJPanelJComponentpaintComponent()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]/APPLET“OBJECT/OBJECT”appletHTML4.0APPLET/APPLET.2——appletHTML2——appletHTMLARCHIVE=archiveList[File1,File2,…]AppletCODEBASE=codebaseURLAppletURLAppletgetCodeBase()AppletHTMLgetCodeBase()getDocumentBase()CODE=appletFileApplet.classcodebaseURLNAME=appletInstanceNameAppletAppletgetAppletContext()Applet2——appletHTMLALT=alternateTextAppletalternateTextWIDTH=pixelsHEIGHT=pixelsAppletALIGN=alignmentAppletHTMLleft,right,top,texttop,middle,absmiddle,baseline,bottom,absbottomVSPACE=pixelsHSPACE=pixelsAppletHTML2——appletHTMLPARAMNAME=appletParameter1VALUE=valuePARAMappletAppletgetParameter()PARAMPARAMmain()Stringargs[]getParameterInfo()PARAMHTMLPARAMgetParameter()alternateHTMLAppletalternateHTMLHTML2——appletHTMLpublicclassAppletParaextendsApplet{Strings1,s2;publicvoidinit(){s1=getParameter(p1);s2=getParameter(p2);}publicvoidpaint(Graphicsg){g.drawString(s1,10,10);g.drawString(s2,10,30);}}HTMLHEADTITLEAppletParameterTest/TITLE/HEADappletcode=“AppletPara.classwidth=300height=300paramname=p1value=1111111paramname=p2value=2222222/applet/HTMLApplets1=getParameter(p1);HTMLAppletparamname=p1value=1111111AppletPara.java3——paint()update()repaint()AppletAWTAWTAppletpaint()update()repaint()AppletAWTpaint()repaint()3——appletAppletAWTSimpleClick.javaswitchTest.javaAppletInOut.javaJApplet6.16P442CalculatorJFrame.java4JavaJava“*.au”“*.wav”,“*.aif”“*.midi”“rfm”AppletApplicationAppletpublicvoidplay(URLurl)publicvoidplay(URLurl,Stringname)play(getCodeBase(),“boing.au”);4java.applet.AudioClipAudioClippublicvoidplay()publicvoidloop()publicvoidstop()AudioClipnewAppletAppletpublicAudioClipgetAudioClip(URLurl)publicAudioClipgetAudioClip(URLurl,Stringname)AudioClipAudioClippublicclassSoundPlayextendsApplet{AudioClipsound;publicvoidinit(){try{sound=getAudioClip(getDocumentBase(),spacemusic.au);}catch(Exceptione){}}publicvoidstart(){sound.loop();}publicvoidpaint(Graphicsg){g.drawString(“...”+spacemusic.au,5,10);}publicvoidstop(){sound.stop();}}4publicclassSoundPlay1extendsApplet{publicvoidstart(){play(getDocumentBase(),spacemusic.au);}publicvoidpaint(Graphicsg){g.drawString(“...”+getDocumentBase()+:spacemusic.au,5,10);}}SoundPlay.javaSoundPlay1.java5Javajava.awtjava.awt.imagejava.appletImageJavagifjpegpngImagenewAudioClipAppletApplication5——AppletApplicationAppletURLURLpicurl=newURL(“”);AppletpublicImagegetImage(URLurl)publicImagegetImage(URLurl,Stringname)Imageimg1=getImage(picurl);Imageimg2=getImage(getCodeBase(),“img2.gif”);5——Applicationjava.awtToolkitpublicabstractImagegetImage(Stringfilename)publicabstractImagegetImage(URLurl)ToolkitToolkitgetDefaultToolkit()getToolkit()Imageimg1=Toolkit.getDefaultToolkit().getImage(picurl);Image
本文标题:46Java第07章--1(JavaApplet)
链接地址:https://www.777doc.com/doc-4211460 .html