Home
  · Order
  · Resellers
  · Contact us
  · Web tips
  · About
Shareware
  · PMVR
  · SlideShow
  · GoRound
Java Tools
  · JexePack
  · Jobfuscate
  · MakeInstall
Affordware
  · PhotoFinder
  · PrintEnvelope
  · WinOpen
  · Label
Java Applets
  · Reference
  · Scripting
  · ControlPad
Learning + Fun
  · NX 101
  · Pano Help
  · Bug Free C
  · Space Rocks
 
DuckwareQuality by Design
 You are here: Duckware » Java Applets » Reference   Contact us  
JavaTM Applet Reference
1. The Java <APPLET> HTML Tag
2. Applet Security Model
3. Technical Notes

 
  1. The Java <APPLET> HTML Tag
<applet
    code=class-filename
    width=pixels
    height=pixels
    archive=jar-file
    name=instance-name
    codebase=url
    align=alignment
    vspace=pixels
    hspace=pixels
    MAYSCRIPT
    >
  <param name=parameter1 value=value1>
  <param name=parameter2 value=value2>
  . . .
  alternateHTML
</applet>
To embed any Java applet within an HTML web page, you must use the <APPLET> tag. See the table to the right for the <APPLET> tag syntax (grayed options are optional; bold text is used as-is; italic text is information that you must provide). code=class-filename -- code="pmvr.class" -- The filename of the applet to load (which always ends in .class). It will load from the directory/folder listed by the codebase attribute listed below.

width=pixels -- width=500 -- The width, in pixels, of the applet. This may also be a percentage, like 20%, but rarely is.

height=pixels -- height=250 -- The height, in pixels, of the applet. This may also be a percentage, like 20%, but rarely is.

archive=jar-file -- archive="pmvr.jar" -- The name of a jar file, which contains the *.class files for you applet. Note that files in the JAR must be in stored format (no compression). Otherwise, if you use compression, you limit yourself to Java 1.1 or later compatibility.

name=instance-name -- name="pmvr" -- Your name for the applet, which can be any text that makes sense to you. This allows applets within a web page to find each other and it allows for you to control the applets via JavaScript. This attribute is optional.

codebase=url -- codebase=".." -- The URL to the directory/folder containing the applet code (class files). An absolute URL can be specified (useful for hosting PMVR tours on multiple domains). A relative URL allows the applet to work on both web servers and the local file system. The relative URL is relative to the document's base URL defined by the BASE tag. If the document does not define a BASE tag, it is relative to the directory/folder containing the HTML file.

align=alignment -- align="left" -- The alignment of the applet. It behaves (and has the same options) as the IMG tag align attribute. This attribute is optional.

vspace=pixels -- vspace=3 -- The vertical space, in pixels, between the applet and surrounding text. It behaves the same as the IMG tag vspace attribute. This attribute is optional.

hspace=pixels -- hspace=3 -- the horizontal space, in pixels, between the applet and surrounding text. It behaves the same as the IMG tag hspace attribute. This attribute is optional.

MAYSCRIPT -- This attribute allows you to use JavaScript within an applet. If you want to use JavaScript, you must grant the applet access to JavaScript by using the MAYSCRIPT attribute, otherwise the applet is not permitted to use JavaScript. If you use MAYSCRIPT on one applet in a web page, you will need to use MAYSCRIPT on all applets in the web page. Please refer to the 12/30/1999 tech note [§3] for details.

<param name=parameter value=value> -- Applet parameters are used to configure an applet. Just use as many param tags as needed to configure the parameters (the parameters are always specific to the particular applet you are using). Please note that param tags are defined within the APPLET tag.

AlternateHTML -- If the <APPLET> tag is not supported by a web browser, the HTML in this section will be displayed. Otherwise, the applet is shown and the HTML in this section is ignored.

For more information about the <APPLET> tag, visit Sun's Applet tag reference.
 
  2. The Java Applet Security Model
A Java VM (virtual machine) is what allows Java applets to run within web browsers. And all modern web browsers come with a Java VM. Java applets are safe to run on your computer because the Java VM prevents a Java applet from accessing resources (files/network/memory/etc) that it is not authorized to access. Applets can be run in a web browser either from a web server, or from the local file system (disk/CD).

Web Server: When a Java VM runs a Java applet from a web server, the Java applet is authorized to access any file on the web server that the applet came from, but the applet can not access any file on another web server or any file on the local file system (your PC).

Local File System: However, when a Java VM runs a Java applet from a local file system (your hard drive), the Java applet is authorized to access only files in the directory that the applet came from (or any subdirectories). Also, the Java VM prevents an applet from accessing files in the root of any drive/CD, as detailed in the 06/20/2000 tech note [§3], as operating system (OS) configuration files (config.sys, autoexec.bat, etc) are usually located there.

For example, the following table summarizes what an applet, running from an HTML file test.html in the tours directory (with the class files placed in the same tours directory) is allowed to access:
Can an applet in test.html (in tours folder) access...
this image when run from http://www.xyz.com/tours/c:/tours/
../pan1.jpgyesNO
../images/pan2.jpgyesNO
./pan3.jpgyesyes
./images/pan4.jpgyesyes
http://www.xyz.com/any.jpgNONO
Notice the discrepancy in access to pan1.jpg and pan2.jpg. Depending upon where test.html is accessed from (a web server or the local hard drive), access to the same image can be either allowed or denied. The problem is that running from the local hard drive is more restrictive than running from a web server. Because when running from a local hard drive, only files in the same directory as the applet class files (or subdirectories) can be accessed by the applet.

With proper planning, and by using the Java applet codebase tag, this problem can be avoided. Namely, create all tours within a directory tree and use the codebase attribute within any <APPLET> tags [§1] in HTML to refer back to the one set of Java class files in the root of the directory tree you created.
 
  3. Java Applet Technical Notes
Java Console TIP: If you are experiencing problems with an applet, the first step is to open the 'Java Console' in your browser to check for error messages:
  • Internet Explorer (Sun's Java): The Java Console option appears under the Tools menu.
  • Firefox: Right click on the Java tray icon and select 'Java Console'.
  • Netscape Communicator: The Java Console is located in the 'Tools / Web Development' menu (or under 'Communicator' menu in older versions).
  • Internet Explorer (Microsoft Java): The Java Console must first be enabled in 'Tools / Internet Options / Advanced / Microsoft VM / Java console enabled'. After restarting your browser, the 'Java Console' option will be available under the 'View' menu.
03/28/2006 -- Activating ActiveX Controls (Java) in Internet Explorer -- Microsoft has changed how user's interact with ActiveX (Java) controls on web pages. Previously, you could interact immediately with controls. However, now there is an extra click. Full details and a workaround. NOTE: the need for this extra click has been removed by Microsoft in April 2008.

01/04/2006 -- Internet Explorer on Mac should no longer be used -- Microsoft's Internet explorer for the Mac is no longer a product. Apple's Safari web browser should be used instead.

02/19/2001 -- Java Applets Cannot Be JavaScript'ed in Mac Internet Explorer -- Microsoft Article ID Q190283 has complete details. In summary, Microsoft does not support JavaScript to Java communication on the Mac. However, please note that Netscape on the Mac and Apple's Safari web browser both do support scripting. To work around this problem, use a web browser that works, or use Native scripting instead of JavaScript scripting.

10/30/2000 -- Do not use spaces in filenames -- Do not use spaces in the filenames of images, etc (possible under a Windows server) as it appears that this can cause problems with some browser / server combinations. Namely, using a URL with a space works under IE (the space is automatically converted to %20), but fails under Netscape.

09/08/2000 -- Netscape cannot read some JPEGs -- Some people have reported that a panorama displays fine in Internet Explorer, but it does not appear when using Netscape Navigator (and that the Netscape java console window reports a "sun.awt.image.ImageFormatException: Image too wide for this implementation" error). This particular problem has been traced to Netscape being unable to read the JPEG at all. To test this, create a URL that points directly to the JPEG image file on the server and test under both Netscape and Internet Explorer. If it does not appear in Netscape but it does within Internet Explorer, then you have run into this problem. The graphics program you are using is producing a JPEG that Netscape is unable to read! Whether this is a problem with the program you are using to write the JPEG (but Internet Explorer works) or with Netscape is unknown. The work-around is to use another graphics program to write the JPEG.

06/24/2000 -- Avoid using transparent GIF images -- Make sure that you avoid using transparent GIF images in applets, if possible. It appears that many Java VM's take a significant performance hit in order to display transparent GIF images. While transparent GIF images do work, they may dramatically show down the applet and cause jerky displays.

06/20/2000 -- Files in the root of a drive/CD cause security errors -- If you attempt to locate class or image files into the root directory of a drive or CD, you will experience problems due to the Java applet security model [§2] (that prevents applets from accessing the root of a drive or CD). The work-around is to move your class files and images into a directory/folder.

12/30/1999 -- MAYSCRIPT and Netscape -- If you use the MAYSCRIPT applet tag on one applet, you must use the MAYSCRIPT tag on all applets on a web page. This is due to a bug in the Netscape web browsers. If you use MAYSCRIPT in only one applet, a second applet can no longer communicate with the first. Please note that this bug only exists in the Netscape browsers and not in the Microsoft browsers.
Copyright © 2000-2013 Duckware