A Basic Applet Example


Applet Overview

An applet is a Java program that can be embedded in an HTML page with an <applet> or <object> tag and hosted on a web server. When a user accesses an HTML page that contains an embedded applet, the applet code is downloaded to the user’s machine and the applet is executed within the web browser’s Java Virtual Machine or Java Plug-In. Applet code accessed and executed in this fashion is generally considered to be untrusted code, and as such is run under tight security restrictions.

An applet can also be run locally either in a browser or with the help of a special application called an AppletViewer. Security restrictions are eased somewhat for locally-run applets but their capabilities are still limited when compared with normal Java applications.

The Benefits Of Using Applets

In spite of increased security restrictions and the resulting reduced functionality, the use of applets offers major benefits. The primary benefit derived from using applets is ease of distribution. Normal Java applications must be installed on each client machine. They can be downloaded from a host computer, for sure, but you are assuming your user-base is computer savvy. Also, any changes to the client code requires another round of distribution.

Applets, on the other hand, can be served from a web page. Updates to an applet are posted in one location and the next time a user accesses that page they will use the updated program.

<applet> Vs. <object> Tags

The <applet> tag is deprecated in the HTML 4.0 specification, superseded by the <object> tag. However, in the interest of backward compatibility, browser creators are enjoined to implement the <applet> tag and most still do. In this chapter I will only demonstrate the use of the <applet> tag. Use of the <object> tag is left as an exercise at the end of the chapter.

Browser JVM Vs. Java Plug-In

There are many different types of browsers in use on the internet at any given instant, some new, many old. Sun provided a technology that enabled applets to run with newer versions of a Java Virtual Machine than what was originally available when the browser was released. This technology is referred to as the Java Plug-In. For more information about the Java Plug-In refer to the following link: [http://java.sun.com/products/plugin/]




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net