As always, open an xterm and create a lab4 directory under your Labs directory. Also open emacs, and open this document in Mozilla.
HTML is the HyperText Markup Language. It is used to describe how text, images, and multimedia are displayed by Web browsers. In the last lab you used an HTML file to display your applets. In this lab you will learn more about HTML so that you can create a web page containing headings, interesting fonts, lists, and links as well as applets. This handout provides an introduction to HTML.
HTML uses tags to describe the layout of a document;
the browser then uses these tags to figure out how to display
the document. Tags are enclosed in angle brackets and are not
case sensitive. For
<title> is a tag that indicates that this section
contains the title of
the document, and could also be written <TITLE> or <Title>.
Many tags, including
<title>, have corresponding end tags that indicate
where the section ends. The end tags look just like
the start tags except that they start with the character
/, e.g., </title>. So the following text means
that the title of the document is
CPSC 120 Lab 4:
<title>CPSC 120 Lab 4</title>There are a few tags that almost every document will have: <html>, <head>, <title>, and <body>. Here is an example of a simple HTML document:
<html> <head> <title>CPSC 120 Lab 4</title> </head> <body> In this lab you will learn about HTML, which is lots of fun to use. In particular, you will learn how to use fonts, paragraphs, lists, links and applets in a web page. Now you can make your own web page for your friends to visit! </body> </html>Click here to see what this looks like in Mozilla. Change the size of the Mozilla window (click and drag any corner) and see how the text is reformatted as the window changes. Note that the title appears on the title bar of the window, not as part of the document.
The head of a document (everything between <head> and </head>) contains the introduction to the document. The title goes in the head, but for now we won't use the head for anything else. The body of a document (everything between <body> and </body>) contains everything that will be displayed as part of the document. Both the head and the body are enclosed by the HTML tags, which begin and end the document.
This document contains only plain text, but an HTML document can have much more structure: headings, paragraphs, lists, bold and italic text, images, links, tables, and so on. Here is a document containing a heading, two paragraphs, and some fancy fonts:
<html> <head> <title>CPSC 120 Lab 4</title> </head> <body bgcolor="lightgreen"> <h1 align="center">Lab 4 In-Class</h1> There's lots you can do with HTML. You can make the page a pretty color, <u>underline</u> text, or put it in <i>italics</i> or <b>bold</b>. You can also make lists, links, and tables, but we'll get to those later. <p>When you go on to a new topic, you can start a new paragraph. You don't have to worry about indenting or otherwise formatting the paragraph -- the browser will decide that for you. Usually it leaves a blank line. If you just want to go to a new line, without any vertical space, you <br> can <br>do <br> that <br> too. </body> </html>Click here to see what this looks like in the browser.
In this document the <h1> tag creates a level 1 heading. This is the biggest heading; it might be used at the beginning of the document or the start of a new chapter. Level 2 through level 6 headings are also available with the <h2> through <h6> tags.
The <p> tag creates a new paragraph. Most browsers leave a blank line between paragraphs. The <br> tag just goes to the next line, without leaving a blank line. The <b> tag creates bold text, the <i> tag creates italic text, and the <u> tag creates underlined text. Note that each of these tags is closed with the corresponding end tag. The bgcolor attribute on the body tag sets the background color.
Note that line breaks and blank lines in the HTML document do not matter -- the browser will format paragraphs to fit the window. If it weren't for the <P> tag, the blank line between the paragraphs in this document would not show up in the displayed document.
cs.roanoke.eduis set up to look in the
public_htmldirectory under each user's home directory on the Linux server, so you need to create this directory as follows:
chmod a+x .
public_html. Be sure it's all lower case.
chmod a+r public_html
astudentand the file name is
Test.html, the URL for your page is
http://cs.roanoke.edu/~astudent/Test.htmlNow on to the exercise!
In Emacs, open a new file called MyPage.html in your public_html directory. Write a simple web page about things that interest you. Your page should contain at least the following:
When you are done, view your document from Mozilla. Just type in the URL, don't use File | Open Page.
Lists We often want to add a list to a document. HTML provides two kinds of lists, ordered (e.g., 1, 2, 3) and unordered (e.g., bulleted). A list is introduced with the <ol> or <ul> tag, depending on whether it is ordered or unordered. Each list item is introduced with a <LI> tag and ended with the </LI> tag. The entire list is then ended with </ol> or </ul>, as appropriate. The following is an ordered list of instructions for creating a list:
<ol> <li>Type the tag <ol> (if you want an ordered list) or <ul> (if you want an unordered list) <li>For each item in your list, type the <li> tag followed by the text you want in the list. <li>To end the list type the tag </ol> or </ul> (depending on the list type - match the beginning tag) </ol>Click here to see what this looks like in the browser.
Links Links connect one document to another. Links are created in HTML with the <a> tag. When creating a link you have to specify two things:
Visit <a HREF="http://cs.roanoke.edu/Fall2004/CPSC120B">my favorite course!</a> Visit my favorite course!
Tables Tables let you align elements in rows and columns; they can be used in the traditional way to display data, or simply to format page elements. There are three important tags for an HTML table:
<table border=1> <tr> <td>Name</td> <td>Test 1</td> <td>Test 2</td> </tr> <tr> <td>Mickey Mouse</td> <td>78</td> <td>92</td> </tr> <tr> <td>Donald Duck</td> <td>83</td> <td>87</td> </tr> </table>
|Name||Test 1||Test 2|
A few things to note:
Last week you wrote an applet that drew shapes of random sizes in random places on the page and you drew a rectangle with your name in it centered at the bottom of the window. This week you will learn more about how to draw various shapes and place them where you want.
Last week we drew rectangles, ovals,and strings but there's lots more that can be done with Java graphics. For starters, you can draw lines and arcs. All of these shapes can be drawn in outline with the "draw" methods (drawRect, drawArc, etc), or drawn in filled in form with the "fill" methods (fillRect, fillArc, etc).
Refer to the list of graphics method on page 100, and read the description on pages 99-102. Pay particular attention to how an arc is defined (note the diagram on page 102).
Now save files MoreShapes.java and MoreShapes.html to your lab4 directory. Look at the .java file, then compile it and view it using the appletviewer. To be sure you understand the arc methods open MoreShapes.java in emacs and do the following:
Now add your face to the web page you created earlier in the lab. You will do this using the <APPLET> tag that is in the .html file you are using with the applet viewer -- you can just copy it out of that file and paste it into your other file. The applet will appear wherever you insert the applet tag. Note that you will have to copy the Face.class file to your public_html directory for the web server to find it. Of course, the web page that you created earlier should already be in that directory.
tar czf lab4.tgz .) and send the tar file to your instructor. Be sure the subject line says cpsc120 lab4.