Download the JDK
Search the Tutorials
Hide the TOC
Trail: Deployment
Lesson: Applets
Section: Deploying Applets
Applets
Getting Started with Applets
Importing Classes and Packages for Applets
Defining an Applet Subclass
The Life Cycle of an Applet
Methods for Milestones
Methods for Drawing and Event Handling
Methods for Adding UI Components
What Applets Can and Can't Do
Taking Advantage of the Applet API
Finding and Loading Data Files
Displaying Short Status Strings
Displaying Documents in the Browser
Sending Messages to Other Applets
Playing Sounds
Defining and Using Applet Parameters
Deciding Which Parameters to Support
Writing the Code to Support Parameters
Giving Information about Parameters
Using the APPLET Tag
Practical Considerations When Writing Applets
Security Restrictions
Creating a User Interface
Creating a GUI
Displaying Diagnostics to the Standard Output and Error Streams
Getting System Properties
Threads in Applets
Threads in Applets: Examples
Working with a Server-Side Application
A Simple Network Client Applet
Using a Server to Work Around Security Restrictions
Finishing an Applet
Before You Ship that Applet
The Perfectly Finished Applet
Deploying Applets
General Deployment Considerations
Using the applet Tag
Using the object Tag
Using the embed Tag
Deploying Applets in a Mixed-Browser Environment
Solving Common Applet Problems
Questions and Exercises
Home Page > Deployment > Applets
Deploying Applets in a Mixed-Browser Environment

> You can deploy applets for users of both Internet Explorer and the Mozilla family of browsers in one of two ways:

> - Through pure HTML
> - Through JavaScript

### Using Pure HTML

> When using a pure HTML approach to deploy applets in a mixed-browser environment, note the following:

> - Internet Explorer
>   - Recognizes the `object` tag
>   - Ignores the contents of the `comment` tag
> - Mozilla browsers
>   - Ignore an `object` tag with the `classid` attribute
>   - Interpret the contents of the `comment` tag

> Consider the following example code from an HTML page:

> >     <object
> >       classid="clsid:CAFEEFAC-0016-0000-0000-ABCDEFFEDCBA"
> >       <param name="code" value="Applet1.class">
> >         <comment>
> >           <embed code="Applet1.class"
> >             type="application/x-java-applet;jpi-version=1.6">
> >             <noembed>
> >               No Java Support.
> >             </noembed>
> >           </embed>
> >         </comment>
> >       </object>

### Using JavaScript

> Instead of using the pure HTML approach described above, you can use JavaScript to deploy applets in a mixed-browser environment.

> Through JavaScript, you:

> 1. Detect the user's browser through the `appName` variable.
> 2. Use the `document.write()` method to write a tag based on the value of the `appName` variable:
>    1. If the browser name equals "Netscape", write the `embed` tag.
>    2. If the browser name equals "Microsoft Internet Explorer", write the `object` tag.

> In the following example, the `document.write()` method outputs either an `embed` or `object` tag for each user “on the fly”:

> >     <html>
> >     <script language="Javascript">

> >       var _app = navigator.appName;

> >       if (_app == 'Netscape') {
> >         document.write('<embed code="Applet1.class"',
> >                        'width="200"',
> >                        'height="200"',
> >                        'type="application/x-java-applet;version=1.6">');
> >         }
> >       else if (_app == 'Microsoft Internet Explorer') {
> >         document.write('<OBJECT ',
> >                        'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"',
> >                        'width="200"',
> >                        'height="200">',
> >                        '<PARAM name="code" value="Applet1.class">',
> >                        '</OBJECT>');
> >         }
> >       else {
> >         document.write('<p>Sorry, unsupported browser.</p>');
> >         }

> >     </script>
> >     </html>

> You can use the HTML Converter tool to help with generating `object` and `embed` tags for mixed environments.

Previous page: Using the embed Tag
Next page: Solving Common Applet Problems