|
JAVA APPLETS |
What
is a Java Applet?
Java Applets are small programs designed to run in a web browser.
Typically, they are only a few kilobytes in length and can run in
multiple operating systems (Mac OS, Windows, Unix, etc.). This makes
them ideal for use on the Internet.
What are Java Applets used for?
Applets are usually used to add small interactive components to web
pages (buttons, scrolling text, or a stock ticker) but can also be used
to make larger programs
like a game or word processor. |
|
What do
I need to make an Applet work? |
You
need the Java .class file...
The Java applet usually comes with a .class file (i.e. "joybutton.class"
or "button.class"). This file is the Java program and must be
on your web site for the applet to work. The .class file comes with the
Applet program already made and ready for use. |
You need the
Applet's HTML code
in your web page…
Just having the .class file on your site isn't enough, you need to put
HTML code in the page which will display the applet. This HTML code is
what the Applet program creates. It tells the .class file how to
customize the applet - what colors and images to use, what size it is,
etc. |
|
Java .class Files
A Java .class file is the Java program.
An Applet will not work without a .class file in one form or another. It
needs to be on your web site for the Applet to work.
Important things to know about .class files
The .class file needs to be on the same server as the HTML page with the
applet. They need to be transferred to a web site in binary
mode. If your FTP program is not in binary mode the .class file may
become corrupted.
An unlimited number of applets can run from one .class file. |
Other
extensions for .class files
Java .class files can have other extensions when they are compressed.
Compressed .class files can have the extension .zip or .jar.
Since it is compressed it will decrease the time it takes to load an
Applet on the Internet.
Note: Older browsers do not support .jar or .zip Java
files. If you use one of these files you will need to put both .class
files (compress and uncompress) on your web site. Older browsers will
load the .class files while newer ones load the .jar or .zip file. |
|
The
following is a list of common problems and solutions: |
My
browser says I have a "java.language.null.pointer.exception"
You may be viewing an applet that contains images from your hard drive
with Netscape 4. There is a bug in Netscape that can cause this error
ONLY when an applet with images is viewed from a local hard drive. The
only way I know to fix this is to change the way you open the html file
in Netscape. Try this… Open Netscape, then drag and drop your HTML
file over the Netscape window. This will open the HTML file and
hopefully everything will work. NOTE: I have never seen this problem
when an applet is viewed from the internet so it should NOT affect
visitors to your site.
Try emptying the browser’s cache and history folders. If you are using
Netscape 4 you can empty these folders from the “Preferences” menu
in Netscape. If you are using Internet Explorer the cache is called the
"Temporary Internet Files" folder and can be deleted from the
options menu in Internet Explorer. You should also empty the history
folder from the browsers options menu.
Go to the page that doesn't work. If you are using Internet Explorer 4
hold down control while pressing the reload button. If you are using
Netscape 4 hold down shift while pressing the reload button.
You started the path to an image or sound or HTML file with the letter
of a hard drive ("c:\" etc.) remove the "c:\" .
All I see is a gray box in my browser
The .class file is not in the proper directory or is named
incorrectly... it must be in the same directory as the HTML file and it
must be named joybutton.class not JoyButton.class or joyButton.cla. The
file names are case sensitive.
My browser says I have a "java.lang.ClassFormatError"
The .class file has been corrupted. This happens when the files are
transferred to the internet with your ftp program in ASCII mode instead
of binary mode. Look in your ftp program for a way to switch to binary
mode and re-transfer the files.
My browser says "Applet can't start: class joybutton not
found"
The .class file is not in the proper directory or is named
incorrectly... it must be in the same directory as the HTML file and it
must be named button.class not Button.class or Button.cla. The file
names are case sensitive.
My images do not show up
The names of images are case sensitive.... make sure the names are
exactly the same on both the HTML page and server with your page.
You have an incorrect path to the images.
Something is wrong with the image file. Try re-saving it with a good
draws program or changing the extension.
It opens a new browser window instead of showing the page in the
correct frame
You probably have entered the html page name in the "Target
Frame" text box instead of the frame name specified in your
frameset.
Don't use frame names with the "-" character.
by John Doerfler |
|
Java programs for the
Web
Java’s level of interactivity is
possible because of how Web browsers that can interpret Java programs
for the Web (called applets) operate. In a non-Java-enabled Web browser,
information content is defined in terms of Multipurpose Internet Mail
Extensions (MIME) specifications, which define a variety of multimedia
document formats. This content is specified so that it can be displayed
in the browser or in a helper application (such as images, sound, and
video). The result is that the user chooses and then observes content. A
Java-enabled browser also downloads content defined by MIME
specifications and displays it.
When a Java-enabled browser downloads a Web page containing a Java
applet, indicated by the hypertext tag (<APPLET>), the browser
knows that a Java program (applet) is associated with that tag. The
Java-enabled browser then can download that applet from the information
provider’s Web server. The applet is in a special format called
bytecodes. The Java-enabled browser can interpret these bytecodes and
run them as an executable program on the user’s computer host. The
result is that the user downloads and runs an executable program-not
just content displayed in the Web
browser. Java also uses this same scheme to support programmer-defined
protocols and special document formats.
|
|
Java’s technical
scheme:
- The user sends a request for an HTML
document to the information provider’s Web server.
- The Web server returns an HTML document to the user’s browser. The
document contains the <APPLET> tag that identifies the applet.
- The bytecode corresponding to that applet is transferred to the
user’s host. This bytecode was created previously by the Java compiler
using the Java source code file for that applet.
- The Java runtime system on the user’s host interprets the bytecodes
and provides display.
- The user then can use the applet with no further downloading from the
provider’s Web server. This is because the bytecode contains all the
information necessary to run the applet.
|