Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 91 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
91
Dung lượng
371,76 KB
Nội dung
APPENDIX J an HTML tutorial 731 <CENTER><H1>Students in Action</H1></CENTER> <HR> <CENTER><I>Dedicated to helping our local community by using the volunteer effort of college students.</I></CENTER> <HR> <P>This semester, our planned actions are:</P> <UL> <LI> to help a local food drive for flood victims in the Midwest</LI> <LI> to visit local adult care centers</LI> <LI> to teach Java to grade-school students</LI> </UL> <P>Our group is active, energetic, and always in need of donations of equipment, effort, and money. We are always willing to help staff and plan community events.</P> <P>As always, our president (at x222) is eager and willing to answer questions and hear suggestions on how we can be more active in our community.</P> </BODY> </HTML> Figure J.7 shows the display of this document. As you can see from Fig. J.7, although the content of the Web page has not changed since Fig. J.1, the presen- tation has changed dramatically. links The World Wide Web would not be a “web” without links between documents. A link connects one document to another. The destination of the link can be a local file or a remote file hosted on another computer. Links are displayed in a number of different ways, but the most popular and recognizable is underlined blue text. In most browsers, when you move your pointing device (a mouse or other device) over a link in a graphical browser, the destination of the link is dis- played somewhere on the screen. The most popular browsers display the desti- nation link on the bottom of the display window. 732 APPENDIX J an HTML tutorial The link tag, <A>, takes one attribute that defines its destination. Inside the link tags (also known as anchor tags), the URL of a new document is specified. For example, the following HTML creates two links: figure J.7 Lists and lines added to the Web page APPENDIX J an HTML tutorial 733 <A HREF=”http://duke.csc.villanova.edu/lewis”>Dr. Lewis’ Home Page Link</A> <A HREF=”http://www.yahoo.com”>Yahoo Internet Search Link</A> The text associated with the <A> and </A> tags is what the browser will usually display as underlined blue text. No checking is done on the validity of the desti- nation until the user selects (or clicks on) the link. Therefore when one writes a Web page, all links should be tested (that is, clicked on or exercised). Following the selection of a link by a user, the browser will attempt to load the contents of the destination. When a successful connection is made to the destination link (either as a remote computer or another file on your own computer), the browser will display the contents of the destination page. Links are very useful for breaking up a document based on content. Links have been the driving force behind the popularity of HTML and the Web because they allow users to read documents located on computers throughout the world. The following HTML has five example links in it. The first three represent links to local documents that describe the Students in Action projects and are located on the same server. The fourth link represents an absolute URL, which can refer to any document in the Web. The fifth link is a mailto link. This is a special type of link that allows users to send mail by clicking on the link. In the following case, the mail would be sent to president@breakaway.com. <HTML> <HEAD> <TITLE>Students in Action</TITLE> </HEAD> <BODY> <HR> <CENTER><H1>Students in Action</H1></CENTER> <HR> <CENTER><I>Dedicated to helping our local community by using the volunteer effort of college students.</I></CENTER> <HR> <P>This semester, our planned actions are:</P> <UL> <LI> to <A HREF=”food.html”>help a local food drive</A> for flood victims in the Midwest</LI> <LI> to <A HREF=”adult.html”>visit local adult care centers</A></LI> 734 APPENDIX J an HTML tutorial Figure J.8 shows how a browser would display this page. color and images Some of the most popular browsers (Netscape Navigator and Microsoft Internet Explorer) have introduced common extension attributes to the <BODY> tag to allow a background color or images for the document to be specified. Background images or color can dramatically improve the aesthetic appearance on a color-capable display. The first attribute is the BGCOLOR attribute. This attribute is used to set the background color of the entire document. For example, the following will set the background color to red in an HTML document: <BODY BGCOLOR=RED> There are two basic methods for defining a color in HTML. The first, as seen in the previous example, uses a standard color name. Note that the display of HTML code is solely under the control of a browser; therefore these names are not truly standard but are common color names that most browsers support. Be sure to check all browsers your users may have to see what specific color names are accepted before choosing an appropriate color. A few de facto standard names for colors that are accepted by both Netscape’s and Microsoft’s browsers are black, blue, gray, green, navy, purple, red, yellow, and white. The second method of choosing a color is to change the color name to an RGB value. An RGB value is a sequence of three numbers that represents the amount of red, green, and blue <LI> to <A HREF=”grade.html”>teach Java to grade- school students</A></LI> </UL> <P>Our group is active, energetic, and always in need of donations of equipment, effort, and money. We are always willing to help staff and plan community events.</P> <P>As always, our <A HREF=”mailto:president@breakaway.com”> president</A> (at x222) is eager and willing to answer questions and hear suggestions on how we can be more active in our community.</P> <P>Visit our <A HREF=”http://www.vill.edu”>University Home Page</A>.</P> </BODY> </HTML> APPENDIX J an HTML tutorial 735 that will be used to create the color. The numbers represent the various strength of the colors involved (0=off, 255=full on). The combination of three values pro- duce a specific color. The RGB values are represented as three pairs of hex char- acters preceded by a number sign (#) and surrounded by double quotes. For figure J.8 Links added to the Students in Action Web page 736 APPENDIX J an HTML tutorial example, to represent the color in which red is 50, green is 150, and blue is 255, the <BODY> tag would look like the following: <BODY BGCOLOR=”#3296FF”> There are many good shareware programs available on the Internet that will help you determine the RGB values for a particular color. In addition to setting the background to a single color, it is also possible to tile the background with a particular image. Most graphical browsers have imple- mented an extension to the <BODY> tag that will take a GIF or JPEG image and repeat it both horizontally and vertically (that is, tile it) to create a background pattern. Some images can be fairly simple, such as a single-color image. Others can be more complex, representing a repeating pattern such as bathroom tiles or a stone mosaic. To use an image as a background, use the BACKGROUND attribute in the <BODY> tag and follow it with the name of the image file in quotes. For example, the following piece of HTML code uses the STONE.GIF image as a tiling background image: <BODY BACKGROUND=”STONE.GIF”> Care should be given to the type of image and strength of its colors. Many times, using an interesting image can make the document’s text difficult to read. Many pages on the Web have free images that you can copy and use as back- grounds. Graphic images can be included in an HTML document in other ways as well. Most popular browsers can show both GIF and JPEG image formats. To include an image, use the <IMG> tag. The SRC attribute of the <IMG> tag can be used to describe the URL of the graphic image file. For example, the following HTML fragment will include an image called new.gif: <IMG SRC=”new.gif”> The following HTML code is the Students in Action Web page modified to use an image as a banner that introduces the organization, and a new image to draw attention to a portion of the page that may have changed recently. APPENDIX J an HTML tutorial 737 <HTML> <HEAD> <TITLE>Students in Action</TITLE> </HEAD> <BODY> <HR> <CENTER><IMG SRC=”SIA.gif”></CENTER> <HR> <CENTER><I>Dedicated to helping our local community by using the volunteer effort of college students.</I></CENTER> <HR> <P>This semester, our planned actions are:</P> <UL> <LI> to <A HREF=”food.html”>help a local food drive</A> for flood victims in the Midwest</LI> <LI> to <A HREF=”adult.html”>visit local adult care centers</A></LI> <LI> to <A HREF=”grade.html”>teach Java to grade- school students</A> <IMG SRC=”new.gif”></LI> </UL> <P>Our group is active, energetic, and always in need of donations of equipment, effort, and money. We are always willing to help staff and plan community events.</P> <P>As always, our <A HREF=”mailto:president@wpllabs.com”> president</A> (at x222) is eager and willing to answer questions and hear suggestions on how we can be more active in our community.</P> <P>Visit our <A HREF=”http://www.vill.edu”>University Home Page</A>.</P> </BODY> </HTML> Figure J.9 shows how a browser would display this page. 738 APPENDIX J an HTML tutorial figure J.9 Images added to the Students in Action Web page APPENDIX J an HTML tutorial 739 applets The <APPLET> tag is used to execute an applet in a document. The <APPLET> tag has many possible attributes; however, its only required attribute is the CODE attribute. The CODE attribute names the class file of the applet that should exe- cute in the document. The browser will load that applet’s class file from the same URL as the document that contains the <APPLET> tag. For example, to execute the Marquee applet, the following HTML fragment is used: <APPLET code=Marquee> </APPLET> A browser displaying this HTML code will load the Marquee.class file into the browser and execute it. Other attributes for the <APPLET> tag include: ◗ HEIGHT—used to define the space in pixels reserved for the display height of the applet ◗ WIDTH—used to define the space in pixels reserved for the display width of the applet ◗ CODEBASE—used to define an alternate URL for the location of the class file In this example, we will reserve 50 pixels for the height and 100 pixels for the width. In the following code fragment, we also reset the location of the class code to another site: <APPLET CODE=Marquee WIDTH=100 HEIGHT=50 CODEBASE=”http://www.javasite.com/applets2use”> </APPLET> When inserted between the <APPLET> and </APPLET> tags, the <PARAM> tag allows you to pass parameters to the Java applet at run time. The <PARAM> tag has two required attributes that allow it to pass information to the applet pro- gram. The attributes are NAME and VALUE. By defining a NAME and VALUE pair, the applet can use and decipher the information it is passed at run time. The follow- ing example sends two parameters, a state and city, to the Map applet: <APPLET CODE=Map WIDTH=100 HEIGHT=5 CODEBASE=”http://www.javasite.com/applets2use”> <PARAM NAME=”state” VALUE=”pennsylvania”> <PARAM NAME=”city” VALUE=”philadelphia”> </APPLET> The following HTML code is the Students in Action Web page with an added applet that scrolls a message across the document as the page is browsed: 740 APPENDIX J an HTML tutorial <HTML> <HEAD> <TITLE>Students in Action</TITLE> </HEAD> <BODY BGCOLOR=”WHITE” TEXT=”BLACK”> <HR> <CENTER><IMG SRC=”SIA.gif”></CENTER> <HR> <CENTER><I>Dedicated to helping our local community by using the volunteer effort of college students.</I></CENTER> <HR> <P>This semester, our planned actions are:</P> <UL> <LI> to <A HREF=”food.html”>help a local food drive</A> for flood victims in the Midwest</LI> <LI> to <A HREF=”adult.html”>visit local adult care centers</A></LI> <LI> to <A HREF=”grade.html”>teach Java to grade- school students</A> <IMG SRC=”new.gif”></LI> </UL> <P>Our group is active, energetic, and always in need of donations of equipment, effort, and money. We are always willing to help staff and plan community events.</P> <P>As always, our <A HREF=”mailto:loftus@wpllabs.com”> president</A> (at x222) is eager and willing to answer questions and hear suggestions on how we can be more active in our community.</P> <APPLET CODE=”Marquee.class” WIDTH=500 HEIGHT=50> <PARAM NAME=text VALUE=”Join us for our Spring picnic in April!”> <PARAM NAME=delay VALUE=”100”> <PARAM NAME=bgcolor VALUE=”255255255”> <PARAM NAME=fgcolor VALUE=”000000128”> </APPLET> <P>Visit our <A HREF=”http://www.vill.edu”>University Home Page</A>.</P> </BODY> </HTML> [...]... APPENDIX K java exceptions and errors EmptyStackException (java. util) An attempt was made to reference an element from an empty stack EOFException (java. io) The end of file has been encountered before normal completion of an input operation Exception (java. lang) The root of the exception hierarchy FileNotFoundException (java. io) A specified file name could not be found GeneralSecurityException (java. security)... Unicode Escape Escape Sequence \ n t b r f \ ' " 0-3 0-7 0-7 APPENDIX L Identifier Java Letter Java Letter Java Digit Java Letter a-z A-Z _ $ other Java letter * Unicode Escape * The "other Java letter" category includes letters from many languages other than English Java Digit 0 -9 other Java digit * Unicode Escape * The "other Java digit" category includes additional digits defined in Unicode Unicode Escape*... contains a list of run-time exceptions and errors produced by the Java language and the classes of the Java standard class library It is not an exhaustive list, but it does contain most of the exceptions and errors that arise in programs within the scope of this text exceptions AccessControlException (java. security) Requested access to a critical system resource is denied ArithmeticException (java. lang)... NoClassDefFoundError (java. lang) The definition of a specified class could not be found NoSuchFieldError (java. lang) A specified field could not be found NoSuchMethodError (java. lang) A specified method could not be found OutOfMemoryError (java. lang) The interpreter has run out of memory and cannot reclaim more through garbage collection StackOverflowError (java. lang) A stack overflow has occurred in the Java interpreter... Literal Octal Integer Literal Hex Integer Literal Decimal Integer Literal 0 1 -9 L 0 -9 l Octal Integer Literal 0 Hex Digit 0-7 0 -9 L a-f l A-F Hex Integer Literal 0 ++ X x Hex Digit L l java syntax 757 758 APPENDIX L java syntax Floating Point Literal 0 -9 Exponent Part 0 -9 Float Suffix 0 -9 Exponent Part Float Suffix e 0 -9 f + E F - d D Character Literal Boolean Literal ' any character ' true false... such as dividing by zero ArrayIndexOutOfBoundsException (java. lang) An index into an array object is out of range ArrayStoreException (java. lang) An attempt was made to assign a value to an array element of an incompatible type AWTException (java. awt) A general exception indicating that some problem has occurred in a class of the java. awt package BindException (java. net) A socket could not be bound... ThreadDeath (java. lang) The stop method of a thread has caused a thread (but not the interpreter) to terminate No error message is printed UnknownError (java. lang) An error has occurred in the Java Virtual Machine (JVM) UnsatisfiedLinkError (java. lang) All of the links in a loaded class could not be resolved VerifyError (java. lang) A class failed the bytecode verification procedures VirtualMachineError (java. lang)... problem has occurred in a class of the java. awt package ClassCircularityError (java. lang) A circular dependency was found while performing class initialization ClassFormatError (java. lang) The format of the bytecode in a class file is invalid Error (java. lang) The root of the error hierarchy APPENDIX K java exceptions and errors ExceptionInInitializerError (java. lang) An exception has occurred in... ParseException (java. text) A string could not be parsed according to the specified format 743 744 APPENDIX K java exceptions and errors ProtocolException (java. net) Some aspect of a network communication protocol was not executed correctly RuntimeException (java. lang) The superclass of all unchecked runtime exceptions SecurityException (java. lang) An operation that violates some kind of security measure... method of the Thread class InterruptedIOException (java. io) While one thread was waiting for the completion of an I/O operation, another thread interrupted it using the interrupt method of the Thread class InvalidClassException (java. io) The serialization run time has detected a problem with a class InvalidParameterException (java. security) An invalid parameter has been passed to a method IOException (java. io) . stack. EOFException (java. io) The end of file has been encountered before normal completion of an input operation. Exception (java. lang) The root of the exception hierarchy. FileNotFoundException (java. io) A. zero. ArrayIndexOutOfBoundsException (java. lang) An index into an array object is out of range. ArrayStoreException (java. lang) An attempt was made to assign a value to an array element of an incompatible type. AWTException. Home Page</A>.</P> </BODY> </HTML> K java exceptions and errors This appendix contains a list of run-time exceptions and errors produced by the Java language and the classes of the Java standard class library.