Just as controls placed on forms extend the Form superclass, applets (executable JAVA code that runs on the Web) that you write extend the Applet superclass. | |||||||
java.applet.* is the package to import that contains the definition of the superclass Applet | |||||||
There are 3 interfaces to Applets --
| |||||||
Web pages host applets. To make applets truly portable (that is, so that they can run on Windows machines, UNIX machines or Mac machines), controls that are used should come from the Abstract Window Toolkit (AWT) | |||||||
Security - Applet cannot:
|
![]()
Creating an Applet --
A Closer Look --
import java.awt.*; // required for the abstract window toolkit
import java.applet.*; // required to get the Applet superclass
The HTML Code --
| Design - to create the user interface, | |
| Source - to view the HTML source code, | |
| QuickView - to see what you've created without invoking a browser |
HTML Tags --
| <HTML> | denotes the start of HTML instructions |
| <HEAD> | to document the purpose & author of the HTML |
| <META> | what was used to create the HTML, and keywords, descriptions, etc. |
| <BODY> | home for Java components and what to be displayed |
| <P> | start a new paragraph |
| nbsp; | non-breakable space (always displays a single space) |
| <APPLET code=Applet1.class width=320 height=200> |
specification
of applet to run ... code= name of the JAVA class file width and height = size of display area in pixels |
| Other Applet Tags | codebase
- alternate location of files name - names running applet alt - string to display if JAVA is disabled align - left, right, top, middle, bottom hspace, vspace - space around the applet display area |
| <BR> | break current line (like a carriage return) |
| <HR> | inserts a horizontal line across the web page |
| <TITLE> | the string to display in the title window of the web page |
| <PARAM NAME="label" VALUE="This string was passed from the host"> |
Parameters
passed to the upload at the start of applet execution after it's been downloaded - NAME = specifies the control that will receive the parameter VALUE = the actual value being passeed |
| <PARAM NAME="background" VALUE="008000"> | Set the background color of the Java display area |
| <PARAM NAME="foreground" VALUE="FFFFFF"> | Set the foreground color of the Java display area |
| </tag> | Be sure to add the closing tag for each opening tag you've used. Closing tags begin with a slash (/) |
![]()
Creating an Applet from Scratch --
![]()
Override Methods from Superclasses --
Using the paint class, we'll overload the inherited method --
Download ScratchApplet.ZIP by clicking here
![]()
Created &
Maintained by DrB - Comments welcome.
Last edited on Wednesday, February 18, 2009