Java Applets

Java Applets

Java Applets are Java programs that are invoked by or embedded in Web pages that make them interative.

Differences between Applications and Applets

Applications Applets
Stand alone programs Must be included in web-page or viewed with applet viewer
Can read/write to file system Can't read/write to file system
Can communicate with multiple servers Can ONLY communicate with server where the applet is stored
NA Can't run programs on client's system
Can load programs native to the local platform. Can't load programs native to the local platform



More Info

Applet Viewer Applet Construction Inclusion in Webpage Passing Parameters
Creating an applet is different than an application in that as it appears inside of a webpage, it uses special classes to dispaly information to the screen such as the Graphics class instead of the System class used for applications.
More About Java Applets
  • Every applet must import at least the java.awt.Graphics class, which allows it to draw to the screen.
  • Every applet class must be public and be a subclass of the class Applet in the package java.applet (see examples in text).
  • To display something to the screen a paint() method is needed.
    • If you use the System.out.prinln() it will send its output to a special text console window often called the "Javal Console" in your browser. (you may have the option to show this or not).
  • Other standard methods that take the place of main() in an application are: init() which initializes the applet, start() starts the applet running
  • Notice that in the above examples what we will refer to as the "main" applet class is passed to the applet HTML tag. This class must contain one of the following mehtods: init(), start(), paint()
  • The stop() method is called when the person leaves the webpage containing the java code or hits the stop button when the page is loading. Unfotunately, this does not seem to be standard on each browser.