CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Applets

Applets
Develop and test
HTML page for an applet

How to code the HTML page for an applet

  • The Hypertext Markup Language (HTML) is the language that's used to create web pages.
  • Each HTML tag begins with the tag name and ends with the tag name prefixed by a forward slash.
  • Within a tag, you can set the attributes for the tag.
  • Although HTML isn't case-sensitive, the name of the Java applet class is.

This applet requires version 1.5 or later of Java.

An HTML page that includes the Future Value Calculator applet

<html>
  <head>
    <title>Future Value Calculator applet</title>
  </head>

  <body>
    <h1>Future Value Calculator applet</h1>
    <applet code = "FutureValueApplet.class" width = 240 height = 175>
      <!-- If the browser can't display the applet, display this HTML -->
      <p>This applet requires version 1.5 or later of Java.</p>
    </applet>
  </body>
</html>

Some HTML tags

Tag Description
<html></html> Marks the beginning and end of an HTML document.
<head></head> Marks the beginning and end of the head of the HTML document.
<title></title> Defines the title that's displayed in the title bar of the browser.
<body></body> Marks the beginning and end of the body of the HTML document.
<h1></h1> Displays the enclosed text as a level-1 header.
<p></p> Displays the enclosed text as a paragraph.
<applet></applet> Defines an applet within the HTML page. After you code this tag, you can use the HTML Converter to convert this tag to OBJECT and EMBED tags.
<object></object> Defines an object within the HTML page. Internet Explorer uses this tag to define applets.
<embed></embed> Embeds an application within the HTML page. Netscape uses this tag to define applets.

Some attributes for working with the APPLET tag

Attribute Description
code Specifies the class name of the code to be executed.
width Specifies the width of the applet in pixels.
height Specifies the height of the applet in pixels.

An HTML comment

<!-- This is an HTML comment -->

No Java Support.

Using the Object tag for applet

<html>
  <head>
    <title>Future Value Calculator applet</title>
  </head>

  <body>
<object
  classid="clsid:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA"
  <param name="code" value="FutureValueApplet.class">
    <comment>
      <embed code="FutureValueApplet.class"
        type="application/x-java-applet;jpi-version=1.5.0">
        <noembed>
          No Java Support.
        </noembed>
      </embed>
    </comment>
  </object>
  </body>
</html>
Previous | Future Value Calculator applet | Code | HTML page for an applet | Test with Applet Viewer | Convert HTML page for an applet | Code for the converted HTML page | Test from a Web browser | Next