?? ch3.htm
字號:
<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 3</FONT></H1><H1><B><FONT SIZE=5 COLOR=#FF0000>Building a Spreadsheet 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="#OverviewofAWTPart1" >Overview of AWT: Part 1</A><UL><LI><A HREF="#AWTClasses" >AWT Classes</A><LI><A HREF="#ComponentsandContainers" >Components and Containers</A><LI><A HREF="#Layouts" >Layouts</A><LI><A HREF="#EventHandling" >Event Handling</A></UL><LI><A HREF="#ExceptionClasses" >Exception Classes</A><UL><LI><A HREF="#TheThrowableClass" >The Throwable Class</A><LI><A HREF="#ExceptionClassHierarchy" >Exception Class Hierarchy</A><LI><A HREF="#ExceptionHandlersandThrowableClasses" >Exception Handlers and Throwable Classes</A><LI><A HREF="#WritingCustomExceptionHandlers" >Writing Custom Exception Handlers</A><LI><A HREF="#ClassOrganization" >Class Organization</A><LI><A HREF="#TheCellClass" >The Cell Class</A><LI><A HREF="#TheCellContainerClass" >The Cell Container Class</A><LI><A HREF="#TheFormulaParserClass" >The FormulaParserClass</A><LI><A HREF="#TheFormulaParserExceptionClass" >The FormulaParserException Class</A><LI><A HREF="#TheArgValueClass" >The ArgValue Class</A><LI><A HREF="#TheSpreadsheetCellClass" >The SpreadsheetCell Class</A><LI><A HREF="#TheSpreadsheetContainerClass" >The SpreadsheetContainer Class</A><LI><A HREF="#TheSpreadsheetFrameClass" >The SpreadsheetFrame Class</A><LI><A HREF="#TheSpreadsheetAppletclass" >The SpreadsheetApplet class</A></UL><LI><A HREF="#Summary" >Summary</A></UL><HR><P><FONT COLOR=#000000>This chapter starts with an overview of AWT(the Abstract Window Toolkit) and its general features and thendetails the basic structure of AWT and its most important classes.A discussion of more advanced aspects of exception handling follows.AWT and exception handling will be important in developing thefirst version of the spreadsheet applet, discussed in detail inthe last section of this chapter. The visual and user-interfacefeatures of the applet will rely on AWT. The underlying spreadsheetengine will make active use of exception handling, particularlywhen validating and calculating formulas.</FONT><H2><A NAME="OverviewofAWTPart1"><FONT SIZE=5 COLOR=#FF0000>Overviewof AWT: Part 1</FONT></A></H2><P>AWT forms the basis for graphical user-interface programming inJava. The AWT package offers a large variety of tools for creatinggraphic widgets such as buttons, list boxes, and scrollbars. Agraphics class can be used for two-dimensional drawing operations,such as displaying polygons, painting text, and setting fontsand colors, and graphical operations, such as clipping and scaling.Beyond all this, AWT provides an underlying foundation for interfacingwith the user. A series of methods handle events produced by theuser and the system, such as mouse clicks and keystrokes. In short,AWT gives you a set of tools for writing simple applets and abasis for developing classes that can be used to create more sophisticatedprograms. <A HREF="ch4.htm" >Chapters 4</A>, "Enhancing theSpreadsheet Applet,"and 5, "Adding Graphs and Scrollbarsto the Spreadsheet," will have the other parts of the AWTtutorial.<H3><A NAME="AWTClasses">AWT Classes</A></H3><P>Figure 3.1 illustrates the hierarchy of the most important classesin the AWT package; they are used for a variety of services:<P><A HREF="f3-1.gif" >Figure 3.1 : <I>Hierarchy of significant AWT classes.</I></A><UL><LI><B>Component</B> is the foundation of controls such as buttonsand labels. It is also the superclass of more sophisticated controls,such as dialog boxes, and even the Applet class.<LI><B>Container</B> is a class that contains Components or otherContainers.<LI><B>Panel</B> is a visual Container that can be used to holdother components, such as buttons, list boxes, and other Containers.<LI><B>Applet</B> is the base class for creating an applet. Itstarts the program and ties it to the native browser.<LI><B>Window</B> is used for popup-style components, such asdialog boxes.<LI><B>Font</B> can be used to create fonts customized by suchfeatures as point size and style.<LI><B>Event</B> encapsulates user- and system-initiated events,such as mouse clicks, keyboard strokes, and the shutdown of anapplet.<LI><B>Graphics</B> is mainly used when a Component needs painting.This class encapsulates a wide range of functions, including drawingpolygons, text, and images, plus setting the Fonts and Colorsto create what is drawn.<LI><B>MenuComponent</B> provides the foundation for creatingdrop-down, checkbox, and other menus.</UL><P>Most of these classes are discussed and illustrated in more detailthroughout this and subsequent chapters.<H3><A NAME="ComponentsandContainers">Components and Containers</A></H3><P>Component classes are used for coordinating all aspects of a visualcontrol. A variety of Component methods can be used to processevents, enable or disable a control, set fonts and colors, andmanage the control's visual display. The most widely used Componentswill be those simple ones that are part and parcel of creatinga user interface. These include labels, buttons, list boxes, andchoice menus. However, more sophisticated Component subclassescan be used to manage these primitive controls. The followinglist shows the primitive Component classes; these simpler classesare derived directly from Component.<BR><P><CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%><TR VALIGN=TOP><TD WIDTH=511><I>Primitive Component Classes</I></TD></TR>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -