chapter 2 designing web pages with html javamethods an introduction to object-oriented programming...

29
<h1>Chapter 2</h1> Designing Web Pages With HTML Java Java Methods Methods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. TM

Upload: emil-fleming

Post on 05-Jan-2016

226 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

<h1>Chapter 2</h1>

Designing Web Pages With HTML

JavaJavaMethodsMethods

An Introductionto Object-Oriented Programming

Maria Litvin

Gary Litvin

Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved.

TM

Page 2: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-2

Objectives:

Understand how web pages are put together

Learn basic HTML tags and develop your own web pages

Learn how images and Java applets are added to web pages

Learn some of the Internet terminology

Page 3: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-3

HTML —

HyperText

Markup

Language

Text contains “hot links.” When touched or clicked, a link takes you to the specified place

Formatting commands are embedded in the text as “tags” (e.g., <b> ... </b> makes it bold)

A very limited “language,” just a few dozen tags

Page 4: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-4

HTML from Source to Display

<html>...<body><h1 align="center">HTML</h1>

<p> <i>WYSIWYG</i> stands for What You See Is What You Get...</body></html>

Display (“what you get”):Source (e.g., Ch02.html):

Page 5: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-5

HTML Source is Device- and Platform-Independent. But:

– may be displayed differently according to the capabilities of a particular device (computer screen, printer), its size, resolution, colors, etc.

– may be interpreted differently by different software (Netscape Navigator, Internet Explorer, etc.)

Page 6: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-6

HTML Features

Tags for formatting and positioning text

Tags for lists, tables, embedded pictures, and Java applets

Tags for hyperlinks and “anchors”

Page 7: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-7

HTML Syntax

Each tag is enclosed in angular brackets:

<sometag>

HTML is case-blind: doesn't distinguish between upper case and lower case.

Many tags require a matching closing tag:

<sometag>my text</sometag>

Page 8: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-8

HTML Syntax (cont’d)

Some tags may take attributes:

<p align="center">

Certain characters (<, >, &, ©, etc.) are represented by an “escape sequence.”

<sometag attr="somevalue">

< &lt;> &gt;& &amp;© &copy;

Page 9: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-9

HTML Syntax (cont’d)

Tags can be nested:

<font color="blue"><i>Red Sea</i></font>

Or:<strong>Click

<a href="details.html">here</a> for

details.</strong>

Page 10: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-10

HTML Document Structure<html> <head> <title>...<title> <meta name="author" content="..."> <meta name=”keywords" content="..."> ... </head>

<body> ... <address> ... </address> </body></html>

Info about the document

Info to be displayed

Contact info for webmaster, etc.

Page 11: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-11

Text Layout

<h1>Heading</h1>

<h2>Subheading</h2>

<h6>Sub ... subheading</h6>

<p>New paragraph

<p align="center">Centered

<p>Text<br>New line

<hr width=”95%">

<blockquote>Indented text</blockquote>

Page 12: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-12

Text Formatting<p>Regular <b>Bold</b> <i>Italic</i> <u>Underlined</u>

<p><strong>Emphasis</strong> <cite>Citation</cite>

<p><code>Typewriter font</code><p><big>Big</big> Regular <small>Small</small> <sub>below</sub> <sup>above</sup>

<p><font color="red" size="+2">Big &amp; red</font>

Page 13: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-13

Anchors and Hyperlinks An “anchor” defines a location in the current

HTML document.

An anchor uses an <a> tag with a name attribute:

<a name="panda"><h3>Giant Pandas</h3>

An anchor can be placed anywhere in a document.

An anchor named “panda”

Page 14: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-14

Anchors and Hyperlinks (cont’d)

A hyperlink defines “hot text” and the destination (a URL) to go to when the link is clicked.

A hyperlink uses the <a> tag with an href attribute and a closing </a> tag:

When clicked, takes you to the anchor named “panda”

Only 1630 <a href="#panda">Giant pandas</a> are left in the world.

Page 15: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-15

URLs

URL stands for “Uniform (or Universal) Resource Locator.”

A hyperlink can link to any URL.

A URL can point to an HTML file, a pdf file, an image, audio, or video file, and even to an e-mail address.

A URL can be absolute or relative.

Page 16: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-16

Absolute URLs An absolute URL defines the absolute

location of a resource on the Internet.

Examples:

http://www.myzoo.com/reptiles.html

mailto:[email protected]

Protocol Host computer (web server)

File name

Protocol e-mail address

Page 17: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-17

Relative URLs

A relative URL in a link describes a location relative to the location of the document that holds that link.

Examples:#pandavolleyball.htmlathletics.html#swimteamimages/lucie.jpg../courses/webdesign

Page 18: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-18

URLs in Hyperlinks

Use relative URLs to link to resources on your own web site.

Use absolute URLs to link to resources on other web sites.

Use relative URL

Use absolute URL

Page 19: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-19

Lists<ul><li>Bike</li><li>Car</li><li>Unicycle</li></ul>

<ol><li>Bike</li><li>Car</li><li>Unicycle</li></ol>

<dl><dt>Car</dt><dd>4 wheels</dd><dt>Bike</dt><dd>2 wheels</dd><dt>Unicycle</dt><dd>1 wheel</dd> </dl>

• Car• Bike• Unicycle

1. Car2. Bike3. Unicycle

Car 4 wheels Bike 2 wheelsUnicycle 1 wheel

Page 20: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-20

Images

.gif files

GIF, Graphics Interchange Format

.jpg files

JPEG, Joint Photographic Experts Group

Page 21: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-21

<img src="URL" ...other attributes>

Other attributes (optional):

alt="some text"

align="top/center/bottom"

border="thickness" (0 — no border)

usemap="#mapname"

Page 22: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-22

Images and Hyperlinks

To turn an image into a hot link, surround it with <a href=...> and </a> tags.

To turn different sections of an image into different hot links, define a “map”:

<map name="mapname">

<area shape="circle/rect/square" coords="..."

href="URL">

<area ...>

...

</map>

Page 23: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-23

Tables

Tables can be used to:

– Display data

– Place text and an image side by side– Make narrow columns of text– Box text messages by adding border– Add color background to text boxes

Tables can be nested.

Page 24: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-24

<table ...> Tag Optional attributes:

border="thickness" (0 — no border)

width="n% (or number of pixels)"

cellpadding="number of pixels"(additional space between data and cell border)

cellspacing="number of pixels"(additional space between cells)

Page 25: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-25

<table ...> Tag (cont’d)<table> <th> <td> ... </td> <td> ... </td> ... <td> ... </td> </th>

<tr> <td> ... </td> <td> ... </td> ... <td> ... </td> </tr> ... <tr> ... </tr><caption> ... </caption></table>

Optional caption

Individual cell

Header row (optional)

Regular row

Page 26: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-26

The <applet> Tag

The tag adds a Java applet to the web page.

An applet’s code consists of .class files and may also include images, audioclips, etc.

Only one class, the “main” class, is listed in the <applet> tag.

Page 27: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-27

The <applet> Tag (cont’d)

<applet code="ClassName" width=... height=... alt="some text" codebase="URL">

Your browser is ignoring the &lt;applet&gt; tag

<param name="... " value="... "> <param ...>

</applet>Optional parameters for the applet

Optional attributes

Page 28: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-28

Review: What is a web page? Web site? Java

applet?

What do HTML, WYSIWYG, HTTP stand for?

Define hypertext and HTML source.

Identify the file types by their extensions:

.htm, .txt, .pdf, .jpg, .gif, .wav, .class

Page 29: Chapter 2 Designing Web Pages With HTML JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

2-29

Review (cont’d): Name some document structure tags.

Name some document layout tags.

Name some text formatting tags.

Name the tags for working with hyperlinks.

What types of lists are supported in HTML? What are their respective tags?

Name some tags for working with images, tables, and applets.