Applet
General info
Return to top
Use an applet
An applet is loaded using the browser as follows:
- Load URL
- Load the HTML document
- Load applet classes
- Run the applet
Return to top
Applet class structure
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
java.awt.Panel
java.applet.Applet
- Applet is a subclass of Panel.
- Applet class must be the superclass of any applet.
- Applet's layout manager is FlowLayout.
Return to top
Key Methods
- init()
- start()
- stop()
- destroy()
- paint(), repaint(), update()
Return to top
Life cycle
- init(): Called when the applet is created, used to initialize data values
- start(): Called when the applet becomes visible
- stop(): Called when the applet becomes invisible
Return to top
Use tag to configure and call applet
<applet
[archive=archiveList]
code=appletFile.class
width=pixels height=pixels
[codebase=codebaseURL]
[alt=alternateText]
[name=appletInstanceName]
[align=alignment]
[vspace=pixels] [hspace=pixels]
>
[<param name=appletAttribute1 value=value>]
[<param name=appletAttribute2 value=value>]
. . .
[alternateHTML]
</applet>
- getDocumentBase() – Returns a URL object that describes the directory of the current browser page
- getCodeBase() – Returns a URL object that describes the source directory of the applet class
- getImage(URL base, String target) and
- getAudioClip(URL base, String target) – Use theURL object as a starting point
--play(URL soundDirectory, String soundFile);
--play(URL soundURL);
Return to top
Security
Most browsers prevent the following:
- Runtime execution of another program.
- File I/O (input/output).
- Calls to any native methods.
- Attempts to open a socket to any system except the host that provided the applet.
Return to top
JApplet
Return to top