lecture 18 java and web pages. java savvy browser a browser capable of handling java applets: -...

33
LECTURE 18 Java and Web Pages

Upload: maurice-baldwin

Post on 04-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

LECTURE 18

Java and Web Pages

Page 2: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

Java Savvy Browser

A browser capable of handling java applets:

- Netscape Navigator

- Microsoft Internet Explorer

- Sun Microsystem’s HotJava

Page 3: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

HotJava

The world’s first Java-savvy browser, developed by Sun Microsysttems.

http://java.sun.com/products/hotjava/

Page 4: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

Gamelan

http://www.gamelan.com

It is a reference library. It provides links to external pagesmaintained by the applet and script authors.

Page 5: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.

Page 6: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

Javazines: Electronic Magazines

JavaWorld - http://www.javaworld.com

The Java Resource Center

http://www.idgbooks.com/rc/java

Page 7: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

Support Areas

JavaSoft

http://java.sun.com

The Java FAQ Archives

http://www-net.com/java/faq

Page 8: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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>

Page 9: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

HTML Tags

Check:

http://www.davesite.com

for information regarding html tags.

Page 10: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

HTML Tags

<HTML> - Hypertext Markup Language <P> - paragraph break<BR> - line-break<PRE> preformatted information

Page 11: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.

Page 12: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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>

Page 13: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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

Page 14: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.

Page 15: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.

Page 16: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

Example:

<APPLET CODE=“Marquee.class” HEIGHT = 25 ALT=“ This is a cool applet - too bad you can’t see it!” HSPACE =10 VSPACE=25>

Page 17: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.

Page 18: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.

Page 19: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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”>

Page 20: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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”>

Page 21: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.

Page 22: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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”>

Page 23: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.

Page 24: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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>

Page 25: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

NOTE

The following lines are the alternate HTML:

<A HREF=“http://www.universal.com/”><IMG SRC=“animal.gif”></A>

Page 26: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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); }}

Page 27: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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>

Page 28: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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); }}

Page 29: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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>

Page 30: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

Images

GIF - Graphics Interchange Format

JPEG - Joint Photographic Experts Group

Page 31: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.

Page 32: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.

Page 33: LECTURE 18 Java and Web Pages. Java Savvy Browser A browser capable of handling java applets: - Netscape Navigator - Microsoft Internet Explorer - Sun

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.