- Forward


Applets
in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

What Are They?
Back SMYC Forward
  • Program (in an Object-Oriented Language):
    • A group of cooperating classes with a well-defined entry point (i.e., a method that should be executed first)and, perhaps, a re-entry point and/or an exit point.
  • Applet:
    • Runs inside of a client (e.g., a browser)
    • Entry point is init() and then start()
    • Top-level container is a JApplet (or Applet)
    • Is often delivered using the Internet
Applets in Java
Back SMYC Forward
  • The "main class" extends the JApplet class (or the Applet class)
  • An applet can interact with its "environment" using a AppletContext object
The Applet Lifecycle in Java
Back SMYC Forward
  • When an HTML page containing an <applet> element is loaded for the first time, the appropriate object (i.e., the descendent of the Applet class referred to in the <applet> element is constructed, and its init() and start() methods are called in a thread other than the event dispatch thread.
  • Each time the user leaves the page containing the applet, the stop() method is called (again, not in the event dispatch thread).
  • Similarly, each time the user re-loads the page containing the applet, the start() method is called.
  • When the browser is shut down, the destroy() method is called (again, not in the event dispatch thread).
Embedding Applets in WWW Pages
Back SMYC Forward
  • An Applet is embedded in a WWW page using the <applet> tag in HTML
  • The name of the Applet is passed to the browser using the code attribute
  • The CLASSPATH is passed to the browser using the codebase attribute
  • To pass parameters to an Applet you use the <param> tag in HTML. Each <param> tag has two attributes, a name and a value. These name-value pairs can be retrieved in the Applet using the getParameter() method.
Typical Limitations and Restrictions (of Unsigned Applets)
Back SMYC Forward
  • An Applet can not run a local executable
  • An Applet can not communicate with any machine other that the originating host
  • An Applet can not read or write files
  • An Applet can not obtain information about the local machine other than the version of Java that is being used, the name and version of the operating system, and information about special character usage
There's Always More to Learn
Back -