Upload
maurice-baldwin
View
213
Download
0
Embed Size (px)
Citation preview
LECTURE 18
Java and Web Pages
Java Savvy Browser
A browser capable of handling java applets:
- Netscape Navigator
- Microsoft Internet Explorer
- Sun Microsystem’s HotJava
HotJava
The world’s first Java-savvy browser, developed by Sun Microsysttems.
http://java.sun.com/products/hotjava/
Gamelan
http://www.gamelan.com
It is a reference library. It provides links to external pagesmaintained by the applet and script authors.
Java Applet Rating Service (JARS)
JARS maintains hyperlinks to external Java-powered pages, as Gamelan does, and also ranks the applets in each page it points to.
Javazines: Electronic Magazines
JavaWorld - http://www.javaworld.com
The Java Resource Center
http://www.idgbooks.com/rc/java
Support Areas
JavaSoft
http://java.sun.com
The Java FAQ Archives
http://www-net.com/java/faq
HTML Tags
<HTML>Mountain Twilight <P>Iron Clouds <BR>have moved east.<BR>The mountain is<BR>a black silhouette<BR>the lake<BR>a gold and lavender<BR>bowl of twilight.<BR><PRE> -TFW</PRE>
</HTML>
HTML Tags
Check:
http://www.davesite.com
for information regarding html tags.
HTML Tags
<HTML> - Hypertext Markup Language <P> - paragraph break<BR> - line-break<PRE> preformatted information
HTML Tags - Advanced Features<I> - italic <B> - bold<H3> - level 3 heading , range: 1 through 5<H3><B><I>moved east</I></B></H3>
<IMG> - imageSRC - source<IMG SRC=“coolgraphic.gif”>
Hyperlinks<A HREF=“http://www.water.org/lakes.html> lakes </A>
<A> is called the anchor tag.
Introducing the <APPLET> Tag
The <APPLET> tag is used to embed Java applets in Web pages. It is comprised of several parts.
Format
<APPLET attributes>applet-parametersalternate HTML</APPLET>
Example:
<APPLET CODE=“Marquee.class” HEIGHT=25, WIDTH=450>
Required Applet Attributes
CODE - Specifies the name of the java fileHEIGHT - Specifies the height of the applet in pixelsWIDTH - Specifies the width of the applet in pixels
Optional Applet Attributes
ALIGN - Specifies where the applet is placed on the page in respect to the text around it: left, right, top, texttop, middle, bottom, absbottom, and baseline.
ALT - This attribute specifies alternative text to be displayed if the Java-savvy browser is incapable of executing the applet for whatever reason. If you want to communicate with non-Java browsers, do so by using alternate HTML.
Optional Applet Attributes
CODEBASE - This attribute specifies the base URL for the applet. The applet must be located relative to this URL. If CODEBASE isn’t specified, the applet is expected to reside in the same directory as the Web page.
HSPACE - This attribute specifies the horizontal space surrounding your applet.
NAME - This attribute specifies the symbolic name of the applet, allowing other applets embedded in the same page to locate your applet by name.
VSPACE - This attribute specifies the vertical space surrounding your applet.
Example:
<APPLET CODE=“Marquee.class” HEIGHT = 25 ALT=“ This is a cool applet - too bad you can’t see it!” HSPACE =10 VSPACE=25>
Getting to base
Under normal conditions, the browser expects to find the applet file inside the same directory as the Web page. However, keeping the applet and the Web page in the same directory isn’t always possible.
The optional CODEBASE tag enables you to specify a URL that points to the directory containing your applet. When a Java-savvy browser encounters the CODEBASE attribute, it automatically knows to look for the applet in the whatever directory that attribute points to.
Example
<APPLET CODEBASE=“http://www.universal.com/applets/”CODE=“Marquee.class” HEIGHT=25 WIDTH=450>
In this example, browsers won’t look for the Marquee applet inside the same directory as the Web page containing this <APPLET> tag. Instead, browsers expect the applet to be located on the universal corporation server, inside the applets directory.
Applet Parameters
The second major part of the applet tag, applet parameters, is where one can really customize an applet.
Format:
<PARM NAME=“parameter name” VALUE=“parameter value”>
Example:
<PARAM VALUE=“sndTrack” VALUE=“audio/summer.au”>
In this example, the name of the parameter is sndTrack. The value associated with this parameter, audio/summer.au, is a relative URL( a partial URL pointing to a file or image located relative to the Web page in which the applet itself appears) leading to a sound file.
Some applets may also accept an absolute URL (complete URL provided) for this parameter:
<PARAM VALUE=“sndTrack” VALUE=“http://www.music.org/audio/summer.au”>
Multiple PARMs
Different applets may support any number of different parameters. It’s not unusual, for example, to come across applets that support several different parameters, giving one great flexibility when it comes to configuring them. To supply more than one parameter, all you have to do is enter the parameters one after another.
Example:
<PARM NAME=“font_face” VALUE=“Helvetica”><PARM NAME=“font_size” VALUE=“24”><PARM NAME=“font_italic” VALUE=“yes”><PARM NAME=“font_bold” VALUE=“yes”>
Alternate HTML
Following any parameter tags that you may use, but before the closing </APPLET> tag, there is a special area where you can supply what’s known as alternate HTML.
Example:
<APPLET CODE=“LivingLinks” WIDTH=100 HEIGHT=100><PARM NAME=“image” VALUE=“animal.gif”><PARM NAME=“sound” VALUE=“dolphin.au”><PARM NAME=“URL” VALUE=“http://www.universal.com/”><A HREF=“http://www.universal.com/”><IMG SRC=“animal.gif”></A></APPLET>
NOTE
The following lines are the alternate HTML:
<A HREF=“http://www.universal.com/”><IMG SRC=“animal.gif”></A>
Combining Java and HTML
import java.applet.*;import java.awt.*;public class Hello extends Applet {Label helloLabel = new Label (“Hello everyone…”);public void init( ){ setBackground(Color.yellow); add(helloLabel); }}
Putting an Applet on the Page
<HTML><HEAD><TITLE> Test page for Hello Applet</TITLE></HEAD><BODY><HR>This line of text comes before the applet.<P><APPLET CODE = “Hello.class” WIDTH=300 HEIGHT=500></APPLET><P>This line of text comes after the applet.</BODY></HTML>
Passing Parameters
import java.applet.*;import java.awt.*;public class HelloAgain extend Applet{Label helloLabel = new Label( )String infoString = “null”;public void init( ) { infoString = getParameter(“info”); helloLable.setText(infoString); add(helloLabel); }}
The <APPLET> tag
<APPLET CODE=“HelloAgain.class” WIDTH=100 HEIGHT=100 ALIGN=left><PARAM NAME=info VALUE=“How are you?”></APPLET>
<APPLET CODE=“HelloAgain.class” WIDTH=100 HEIGHT=100 ALIGN=right><PARAM NAME=info VALUE=“Greetings!”></APPLET>
Images
GIF - Graphics Interchange Format
JPEG - Joint Photographic Experts Group
GIF
The GIF format is great at compressing cartoon-like artwork, but not nearly as good as JPEG for compressing photographic quality images.
Interlacing is another feature unique to the GIF format. It enables images to be incrementally drawn on-screen as they come across the wire, so viewers don’t have to wait until the entire image is transmitted.
JPEG
GIF images are currently limited to 256 (8-bit) colors. The JPEG format, on the other hand, supports over 16 million (24-bit) different colors. As a general rule, you should keep the total amount of material to be downloaded per page (text, graphics, sound files, applets, and so on) under 250K.
JPEG
If you have a large number of graphics and more than 250K in total Web page material, consider using the JPEG format simply to gain the highest degree of compression possible. Because images with more than 100 colors tend to compress more efficiently in the JPEG format than with GIF, target those images with the most colors first for JPEG.
Interlacing is not support by JPEG at the moment.