⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch6.htm

📁 JAVA Developing Professional JavaApplets
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<HTML><HEAD><TITLE>developer.com - Reference</TITLE><META NAME="Author" CONTENT="developer.com"><META NAME="Keywords" CONTENT="javascript, ActiveX, VRML, Push, channel,push channel, applet, directory, news, community, developer, internet,intranet, java, java applet, J++, javabeans, java products, tools, javatools, JDK, java development kit, java development environment, JIT,JavaPlan, enterprise tools, JVM, Java Virtual Machine, Java resources, API,browser, java documentation, CDF, Common Desktop Format, RDF, ResourceDescription Framework, Netcaster, Netcast, Castanet, meta-language, metadata,solaris, Solaris, SUN, CGI, Perl, Oracle, database, network, Netscape API,Apache, apache, SSL, mSQL, Netscape, Fasttrack, FastTrack,industry standard, ActiveX bridge, web, internet, site, sitedesign, microsoft, active server pages, asp, iis, nt, win95, 95, html, cgi,frontpage, business, corporate, vbscript, javascript, activex, isapi,database, access, sql, server, www, 3.0, 3.01, 3.02, 3.03, 3.04, 4.0,4.0b2, 4.01, 4.03, 4.04, connection, online, commerce, publisher,publishing, publish, webmaster, dynamic html, dhtml, windows 98, netscape,netscape software, shareware, magazines, jobs, japan, free, freeware, freestuff"><META NAME="description" CONTENT="Developer.com is the leading onlineservice for developers. It includes Gamelan, the official directory for Java, as wellas news, information, tutorials, and directories for other Internet technologiesincluding ActiveX, JavaScript, perl, VRML, Java Beans, push technologies, andother Internet and intranet technologies. Developer.com is also the home ofDeveloper Direct, the Professional Developer's Store, where developers canpurchase and download thousands of Web, authoring and other developmentproducts at some of today's lowest prices."><META NAME="distribution" CONTENT="global"><META NAME="resource-type" CONTENT="document"><META NAME="language" CONTENT="en"></HEAD><BODY BACKGROUND="/images/curve_r-wide.gif" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#DD0000" VLINK="#999999" ALINK="#FF0000"><TABLE><TR><TD VALIGN=TOP WIDTH=120><A HREF="/" ><IMG SRC="/images/masthead_r.gif" WIDTH="100" HEIGHT="78" BORDER="0"ALT="Developer.com Logo"></a></TD><TD><a target="resource window" href="http://adserver.developer.com/cgi-bin/accipiter/adclick.exe/AREA=DCBAN.REF/DT=null"><img src="http://adserver.developer.com/cgi-bin/accipiter/adserver.exe/AREA=DCBAN.REF/DT=null" HEIGHT="60" WIDTH="468" ALT="Click here to support our advertisers"><BR><CENTER>Click here to support our advertisers</CENTER></a></TD></TR></TABLE><!--outer table--><TABLE><!--outer table--><TR><!--outer table--><TD VALIGN="TOP"><!--navbar info --><table><tr><td><A HREF="http://www.developerdirect.com/" ><IMG SRC="/images/button_s.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>SHOPPING</b></font></a></td></tr><tr><td><A HREF="/community/jobs/c_jobs.html"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>JOB BANK</B></font></a></td></tr><tr><td><A HREF="http://www.classifieds2000.com/cgi-cls/display.exe?Developer+computer+searchcomputercategories"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>CLASSIFIEDS</B></font></a></td></tr><tr><td><A HREF="/directories/directories.html"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>DIRECTORIES</B></font></a></td></tr><tr><td><A HREF="/reference/"><IMG SRC="/images/button_r.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>REFERENCE</B></font></a><br><a href="/reference/r_library.html"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000">Online Library</a></font></td></tr><tr><td><A HREF="/classroom/"><IMG SRC="/images/button_r.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>LEARNING CENTER</B></font></a></td></tr><tr><td><A HREF="/journal/"><IMG SRC="/images/button_n.gif" width="15" height="11" BORDER="0"><B><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000">JOURNAL</font></B></a></td></tr><tr><td><A HREF="/news/"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>NEWS CENTRAL</b></font></a></td></tr><tr><td><A HREF="/downloads/"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>DOWNLOADS</b></font></a></td></tr><tr><td><A HREF="/community/" ><IMG SRC="/images/button_c.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><B>COMMUNITY</B></font></a></td></tr><tr><td><A HREF="/calendar/"><IMG SRC="/images/button_d.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>CALENDAR</b></font></a></td></tr><tr><td><A HREF="/about/"><IMG SRC="/images/button_a.gif" width="15" height="11" BORDER="0"><FONT FACE="Arial, Helvetica" SIZE="-1" color="#000000"><b>ABOUT US</b></a></font></td></tr></table><table><tr><td><form action="/subscribe/list.cgi" method=post ><img src="/images/rule.gif" width="100" height="2"><br><B><FONT FACE="Arial, Helvetica" SIZE="-1">Journal:</b></font><br><input name='email' value='your e-mail' size="11"><input type='hidden'  name='state' value='Subscribe'></td></tr><tr><td><input type='submit' value='Subscribe'><br><font size="-1">Get the weekly email highlights from the most popular journal for developers!<br><a href="http://www.developer.com/subscribe.html">Current issue</a><img src="/images/rule.gif" width="100" height="2"><input type='hidden' name='name' value='New Subscriber'></FORM></td></tr></table><!--/navbar--><font size="-1"><A HREF="http://www.developer.com">developer.com</a><BR><A HREF="http://www.developerdirect.com">developerdirect.com</a><BR><A HREF="http://www.htmlgoodies.com">htmlgoodies.com</a><BR><A HREF="http://www.javagoodies.com">javagoodies.com</a><br><A HREF="http://www.jars.com">jars.com</a><BR><a href="http://www.intranetjournal.com">intranetjournal.com</a><br><a href="http://www.javascripts.com">javascripts.com</a><br></font><!--outer table--></TD><!--outer table--><TD VALIGN="TOP"><BLOCKQUOTE><P><img src="/images/header_r.gif" width="440" height="50"><P><MAP NAME ="header_r2.gif.map"><AREA SHAPE ="RECT"      HREF ="/reference/author.html"      COORDS ="361,0,440,29"><AREA SHAPE ="RECT"      HREF ="/reference/basic.html"      COORDS ="254,0,360,29"><AREA SHAPE ="RECT"      HREF ="/reference/help.html"      COORDS ="183,0,251,29"><AREA SHAPE ="RECT"      HREF ="/reference/cool.html"      COORDS ="100,0,181,29"><AREA SHAPE ="RECT"      HREF ="/reference/mybook.html"      COORDS ="0,0,100,29"></MAP><MAP NAME ="header_r1.gif.map"><AREA SHAPE ="RECT"      HREF ="/reference/personalize.html"      COORDS ="339,0,439,29"></MAP><p><font face="Arial,Helvetica" size="-1" color="#006666"><A HREF="/reference/r_library.html"><B>All Categories</A> :</B><b><A HREF="/reference/r_java.html">Java</A></b></font><p>   <META NAME="GENERATOR" CONTENT="Mozilla/3.0b5aGold (WinNT; I) [Netscape]"><H1><FONT COLOR=#FF0000>Chapter 6</FONT></H1><H1><B><FONT SIZE=5 COLOR=#FF0000>Building a Catalog Applet</FONT></B></H1><P><HR WIDTH="100%"></P><P><H3 ALIGN=CENTER><FONT COLOR="#000000"><FONT SIZE=+2>CONTENTS<A NAME="CONTENTS"></A></FONT></FONT></H3><UL><LI><A HREF="#BasicsoftheAppletClass" >Basics of the Applet Class</A><LI><A HREF="#AppletsandHTML" >Applets and HTML</A><LI><A HREF="#AppletsandImages" >Applets and Images</A><LI><A HREF="#AppletsandAudio" >Applets and Audio</A><LI><A HREF="#UndertheAppletHood" >Under the Applet Hood</A><LI><A HREF="#CreatingandReadingaURL" >Creating and Reading a URL</A><LI><A HREF="#ChapterProject" >Chapter Project</A><UL><LI><A HREF="#ClassOrganization" >Class Organization</A><LI><A HREF="#CatalogHTML" >Catalog HTML</A><LI><A HREF="#TheCatalogClass" >The Catalog Class</A><LI><A HREF="#TheCatalogButtonClass" >The CatalogButton Class</A><LI><A HREF="#TheSelectionCanvasClass" >The SelectionCanvas Class</A><LI><A HREF="#TheMediaLoaderClass" >The MediaLoader Class</A><LI><A HREF="#TheMediaLoaderExceptionClass" >The MediaLoaderException Class</A></UL><LI><A HREF="#Summary" >Summary</A></UL><HR><P>In this part of the book, a basic framework will be developedfor creating catalog applications with general kiosk-like features.The application is described as &quot;kiosk-like&quot; becauseit emphasizes the use of images (rather than buttons and menus)to guide you through the various pages of the catalog. Consequently,the catalog will make heavy use of images, a primary subject ofthis part of the book.<P>Since images put a heavy load on the network, smarter methodsare needed for loading them from the server to the client. <A HREF="ch7.htm" >Chapter 7</A>,&quot;Java and Images,&quot; introduces one of Java's most importantfeatures, multithreading, to illustrate some techniques for loadingimages before they are needed, thus making your application faster.The general overview of multithreading will form the foundationsof thread programming, which will be used frequently in the restof the book.<P>The kiosk will also make use of many of the features native toJava's applet classes. These classes make it easy to bring audioand images into your applet. They also give you a way to accessfeatures of the native browser, such as its status bar. One ofthe applet classes also provides a gateway for creating linksto other HTML pages. The discussion of how this works will leadto the illustration of yet another component of Java, the URLclasses. There will be an overview of how to open a stream toother URL objects, such as an image or text file residing on theserver, and how to bring them into your client applet.<H2><A NAME="BasicsoftheAppletClass"><FONT SIZE=5 COLOR=#FF0000>Basicsof the Applet Class</FONT></A></H2><P>This chapter's tutorial focuses on a variety of ways that theApplet class can be used to enhance the way your applet works.Recall that the Applet class provides the foundation for creatingapplets-Java applications that run in a browser environment. Besideslaunching your applet, the Applet class provides many useful services.It can be used to load image and audio files, work with URLs,and access the native browser environment. Since the Applet classis also a component of the AWT package (as was discussed in PartII, &quot;Developing a Spreadsheet Applet with the AWT Package&quot;),Applet objects provide many of the visual features that are partof the standard AWT repertoire, especially using the Graphicsclass for painting text, shapes, and images. Since The Appletclass is a subclass of the AWT Component class, it can handleevents such as mouse events and keystrokes.<P>Four often misunderstood Applet methods are overridden to managethe life cycle of an applet. None of these methods are requiredto be overridden, although their use will generally give you amore stable applet. These are the four methods:<UL><LI><TT><B>init()</FONT></B></TT> This isused to initialize an applet whenever it is loaded. You typicallyoverride this method to set up resources that will be used throughoutan applet, such as fonts, or to initialize variables. This methodis called once and only once during the lifetime of your applet.However, if the applet is reloaded for some reason or another,the <TT>init()</TT> method will becalled again. Some Java literature may lead you to believe thatyou have to <I>always</I> override this method. This is not true!You need to override <TT>init()</TT>only when your applet's circumstances dictate that you should. A good example of this is initializing resources, such as AWTcomponents.<LI><TT><B>start()</FONT></B></TT> This iscalled whenever the HTML document on which an applet resides becomesthe current page of a browser. When an applet is first run, the<TT>start()</TT> method is calledafter <TT>init()</TT>. Unlike thelatter, however, <TT>start()</TT>will be called whenever the user visits the applet's page. Twovery important types of activities should be located in the <TT>start()</TT>method. The <TT>show()</TT> methodof instances of the Frame class are best called in the <TT>start()</TT>method. Since Frames occur outside the confines of an applet page,they will stay onscreen even after you have left the page. Consequently,they should be shown when you enter the page and hidden when youleave (see the <TT>stop()</TT> descriptionmethod that follows). There will be an example in the upcominglistings. The <TT>start()</TT> method

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -