Chapter 8 Introduction to HTML and Applets Fundamentals

  • Slides: 50
Download presentation
Chapter 8 Introduction to HTML and Applets Fundamentals of Java

Chapter 8 Introduction to HTML and Applets Fundamentals of Java

Objectives l l l 2 Understand the basic features of hypertext, hypermedia, and the

Objectives l l l 2 Understand the basic features of hypertext, hypermedia, and the World Wide Web. Use basic HTML markup tags to format text for a Web page. Construct an HTML list and an HTML table to represent a linear sequence of items and a two-dimensional grid of items, respectively. Fundamentals of Java

Objectives (cont. ) l l 3 Use the appropriate markup tags to include images

Objectives (cont. ) l l 3 Use the appropriate markup tags to include images in Web pages. Create links to other Web pages using absolute or relative path names. Convert a Java application to an applet and embed the applet in a Web page. Understand the constraints on applets that distinguish them from Java applications. Fundamentals of Java

Vocabulary l l l l 4 Absolute path name Associative link Definition list External

Vocabulary l l l l 4 Absolute path name Associative link Definition list External image Hyperlinks Hypermedia Hypertext Fundamentals of Java

Vocabulary (cont. ) l l l 5 Hypertext markup language (HTML) Inline image Markup

Vocabulary (cont. ) l l l 5 Hypertext markup language (HTML) Inline image Markup tag Memex Relative path name Uniform resource locator (URL) Fundamentals of Java

Hypertext, Hypermedia, and the World Wide Web l Memex: Theoretical machine proposed by Vannevar

Hypertext, Hypermedia, and the World Wide Web l Memex: Theoretical machine proposed by Vannevar Bush in 1945 that would link information in tables by keys – – Every computer would have a memex that was linked to the memexes on other computers. Associative links between computers: l 6 Could be traced backwards and forwards Fundamentals of Java

Hypertext, Hypermedia, and the World Wide Web (cont. ) l Hypertext: A structure consisting

Hypertext, Hypermedia, and the World Wide Web (cont. ) l Hypertext: A structure consisting of nodes and links between them – l Early hypertext systems: – – 7 Links to other nodes typically displayed to users as embedded, highlighted terms within a given chunk of text Douglas Englebart’s NLS/Augment (1968) Cognetics Corporation’s Hyperties (mid-1980 s) Fundamentals of Java

Hypertext, Hypermedia, and the World Wide Web (cont. ) l Hypermedia: Extended hypertext that

Hypertext, Hypermedia, and the World Wide Web (cont. ) l Hypermedia: Extended hypertext that adds: – – – 8 GUIs Images Sound Animation Applications Fundamentals of Java

Hypertext, Hypermedia, and the World Wide Web (cont. ) l With development of the

Hypertext, Hypermedia, and the World Wide Web (cont. ) l With development of the Internet, people began to think of sharing hypertext across a network of communicating machines. – – l The Web consists of: – – 9 Each node is a page. Each page is linked to the World Wide Web. Servers: House pages of information Clients: Run browsers to access information on servers Fundamentals of Java

Hypertext, Hypermedia, and the World Wide Web (cont. ) l When you view a

Hypertext, Hypermedia, and the World Wide Web (cont. ) l When you view a page in a browser and click on a link: – – 10 The browser sends a message to the node’s machine, requesting a transfer of its information. If the request is successful, the information at the node is downloaded to the user’s browser. Fundamentals of Java

Hypertext, Hypermedia, and the World Wide Web (cont. ) l Networked hypermedia systems require

Hypertext, Hypermedia, and the World Wide Web (cont. ) l Networked hypermedia systems require uniform means of: – – 11 Representing data via a machine-independent hypertext markup language Assigning node addresses using machineindependent uniform resource locators (URLs) Fundamentals of Java

Hypertext, Hypermedia, and the World Wide Web (cont. ) l Networked hypermedia systems require

Hypertext, Hypermedia, and the World Wide Web (cont. ) l Networked hypermedia systems require uniform means of (cont. ): – – 12 Transmitting information from site to site using machine-independent network transmission protocols Displaying information with browsers from different vendors Fundamentals of Java

Overview of the Hypertext Markup Language l l 13 Hypertext markup language (HTML): Machine-independent

Overview of the Hypertext Markup Language l l 13 Hypertext markup language (HTML): Machine-independent language for representing information in a networkedbased hypermedia system Markup tags: Indicate format of textual elements or links to other nodes Fundamentals of Java

Overview of the Hypertext Markup Language (cont. ) 14 Figure 8 -1: The Internet

Overview of the Hypertext Markup Language (cont. ) 14 Figure 8 -1: The Internet Fundamentals of Java

Overview of the Hypertext Markup Language (cont. ) Figure 8 -2: Simple Web page

Overview of the Hypertext Markup Language (cont. ) Figure 8 -2: Simple Web page 15 Fundamentals of Java

Overview of the Hypertext Markup Language (cont. ) l 16 HTML for the simple

Overview of the Hypertext Markup Language (cont. ) l 16 HTML for the simple Web page: Fundamentals of Java

Overview of the Hypertext Markup Language (cont. ) l The document must be stored

Overview of the Hypertext Markup Language (cont. ) l The document must be stored in a file having the extension: – – l Markup tags begin with a left angle bracket (<) and end with a right angle bracket (>). – 17 “. html” on a UNIX system “. htm” on a Windows system Not case sensitive Fundamentals of Java

Overview of the Hypertext Markup Language (cont. ) l Tags often occur in pairs.

Overview of the Hypertext Markup Language (cont. ) l Tags often occur in pairs. – – l Tags can include attributes. – 18 Mark the start and end of a tag. <TITLE> and </TITLE> <P ALIGN=CENTER> Fundamentals of Java

Overview of the Hypertext Markup Language (cont. ) 19 Table 8 -1: Basic HTML

Overview of the Hypertext Markup Language (cont. ) 19 Table 8 -1: Basic HTML markup tags Fundamentals of Java

Overview of the Hypertext Markup Language (cont. ) l 20 Minimal document structure: Fundamentals

Overview of the Hypertext Markup Language (cont. ) l 20 Minimal document structure: Fundamentals of Java

Overview of the Hypertext Markup Language (cont. ) l l l HTML tag: Informs

Overview of the Hypertext Markup Language (cont. ) l l l HTML tag: Informs browser that it is dealing with an HTML document HEAD tag: Identifies first part of document TITLE tag: Identifies document’s title – – l 21 Displayed at top of browser’s window Used during searches for the document BODY tags: Enclose information provided by the HTML document Fundamentals of Java

Simple Text Elements l Headings: Six levels – – – l 22 H 1

Simple Text Elements l Headings: Six levels – – – l 22 H 1 through H 6 Different font size and style than normal text <Hnumber>Heading Text</Hnumber> Paragraphs: Contained within <P>…</P> Fundamentals of Java

Simple Text Elements (cont. ) l Forced line breaks: tag l Preformatted text: Display

Simple Text Elements (cont. ) l Forced line breaks: tag l Preformatted text: Display text “as is” – 23 Contained within <Pre>…</Pre> tags Fundamentals of Java

Character-Level Formatting 24 Table 8 -2: Some character format tags Fundamentals of Java

Character-Level Formatting 24 Table 8 -2: Some character format tags Fundamentals of Java

Character-Level Formatting (cont. ) l Escape sequences: Codes to display special characters Table 8

Character-Level Formatting (cont. ) l Escape sequences: Codes to display special characters Table 8 -3: Some escape sequences 25 Fundamentals of Java

Lists l l l 26 Unordered (bulleted) lists: Tag <UL> Numbered (ordered) lists: Tag

Lists l l l 26 Unordered (bulleted) lists: Tag <UL> Numbered (ordered) lists: Tag <OL> Definition (association) lists: Tag <DL> For bulleted and ordered lists, use <LI> tag for each element in the list. For definition lists, use <DT> tag for terms and <DD> tag for definitions. Fundamentals of Java

Lists (cont. ) 27 l Unordered list example: l Definition list example: Fundamentals of

Lists (cont. ) 27 l Unordered list example: l Definition list example: Fundamentals of Java

Lists (cont. ) l 28 Nested list example: Fundamentals of Java

Lists (cont. ) l 28 Nested list example: Fundamentals of Java

Lists (cont. ) Figure 8 -4: Nested list 29 Fundamentals of Java

Lists (cont. ) Figure 8 -4: Nested list 29 Fundamentals of Java

Linking to Other Documents l Links (hyperlinks or hypertext references): Allow readers to move

Linking to Other Documents l Links (hyperlinks or hypertext references): Allow readers to move to other pages in the Web – Anchor tag: <A> – Can appear anywhere within any html document Hyperlinked text is highlighted in some way when displayed: – l Underlined 30 or a different color, or both Fundamentals of Java

Linking to Other Documents (cont. ) l Steps to place a link in a

Linking to Other Documents (cont. ) l Steps to place a link in a document: – 1. Identify target document that will be at link’s other end. l Path – – name or URL 2. Determine text that labels the link in the browser. 3. Place this information within an anchor. l <A HREF="target document identifier">text of link</A> 31 Fundamentals of Java

Linking to Other Documents (cont. ) l Path names: – – l Uniform resource

Linking to Other Documents (cont. ) l Path names: – – l Uniform resource locator (URL): Used to specify files on another computer – 32 Absolute path name: Specifies exact position of the file in the computer’s directory structure Relative path name: Specifies a document’s position relative to that of the currently displayed document http: //server name/document path name Fundamentals of Java

Linking to Other Documents (cont. ) Table 8 -4: Relative path names to My.

Linking to Other Documents (cont. ) Table 8 -4: Relative path names to My. Page. html 33 Fundamentals of Java

Multimedia l Inline images: Displayed when user opens a page – <IMG SRC="Image. Location">

Multimedia l Inline images: Displayed when user opens a page – <IMG SRC="Image. Location"> – Images can be in GIF or JPEG format. Size attributes: – l – Alignment attribute: l 34 <IMG SRC="mypicture. gif" HEIGHT=100 WIDTH=100> <IMG SRC="mypicture. gif" ALIGN=CENTER> Fundamentals of Java

Multimedia (cont. ) l External images: Not displayed until user clicks on a link

Multimedia (cont. ) l External images: Not displayed until user clicks on a link – – l 35 Use the anchor tag <A HREF="mypicture. gif">Sample picture</A> Colors and backgrounds: String of three, two-digit hexadecimal numbers specifies a color by indicating RGB value. Fundamentals of Java

Multimedia (cont. ) Table 8 -5: Some hypermedia filename extensions 36 Fundamentals of Java

Multimedia (cont. ) Table 8 -5: Some hypermedia filename extensions 36 Fundamentals of Java

Tables Figure 8 -8: A table 37 Fundamentals of Java

Tables Figure 8 -8: A table 37 Fundamentals of Java

Tables (cont. ) Table 8 -6: Table format tags 38 Fundamentals of Java

Tables (cont. ) Table 8 -6: Table format tags 38 Fundamentals of Java

Tables (cont. ) Table 8 -7: Table attributes 39 Fundamentals of Java

Tables (cont. ) Table 8 -7: Table attributes 39 Fundamentals of Java

Tables (cont. ) l 40 Typical table format: Fundamentals of Java

Tables (cont. ) l 40 Typical table format: Fundamentals of Java

Applets l A Java application that runs in a Web page – Two components

Applets l A Java application that runs in a Web page – Two components necessary: HTML document that contains an applet markup tag l Byte code file for the applet l l An applet markup tag has the following form: – l 41 <APPLET CODE="byte code file name" WIDTH=width HEIGHT=height></APPLET> Applets present a graphical user interface. Fundamentals of Java

Applets (cont. ) 42 Figure 8 -9: Applet within a Web page Fundamentals of

Applets (cont. ) 42 Figure 8 -9: Applet within a Web page Fundamentals of Java

Applets (cont. ) l 43 HTML code: Fundamentals of Java

Applets (cont. ) l 43 HTML code: Fundamentals of Java

Applets (cont. ) l Converting a Java application to an applet: – – 44

Applets (cont. ) l Converting a Java application to an applet: – – 44 Replace the name JFrame with the name JApplet at the beginning of the class definition (extends JApplet). Replace constructor by the method init: Fundamentals of Java

Applets (cont. ) Example 8. 2: Applet with a specialized panel 45 Fundamentals of

Applets (cont. ) Example 8. 2: Applet with a specialized panel 45 Fundamentals of Java

Applets (cont. ) l Sun’s applet viewer: Allows programmer to run an applet and

Applets (cont. ) l Sun’s applet viewer: Allows programmer to run an applet and view just its GUI – – Without the surrounding Web page Steps to use applet viewer: l Compile the Java source program as usual. l Create HTML file with at least the minimal applet tag for the applet. l At the command line prompt, run appletviewer <html file name>. 46 Fundamentals of Java

Applets (cont. ) l Constraints on applets: – – – l 47 Cannot access

Applets (cont. ) l Constraints on applets: – – – l 47 Cannot access local files Byte code file and html file should be in same directory. Dialog boxes may appear differently. Loading images into an applet: Fundamentals of Java

Applets (cont. ) l Passing parameters to applets: – l 48 Example HTML: Accessing

Applets (cont. ) l Passing parameters to applets: – l 48 Example HTML: Accessing the parameter from the applet class: Fundamentals of Java

Summary l l l 49 The World Wide Web is a hypermedia system that

Summary l l l 49 The World Wide Web is a hypermedia system that allows users to navigate among and use resources in a nonlinear manner. HTML tags can format text for Web pages. Links to other pages using absolute or relative path names can be included in HTML elements. Fundamentals of Java

Summary (cont. ) l l l 50 Web pages can contain applets or Java

Summary (cont. ) l l l 50 Web pages can contain applets or Java applications that are downloaded from a Web server and run in the user’s Web browser. A few steps are needed to convert an application to an applet. Applets have most of the functionality of applications, including the GUI, but they lack file access to the user’s disks. Fundamentals of Java