The HTML APPLET TAG


How to run an Applet Program

An Applet program is compiled in the same way as you have been compiling your console programs. However there are two ways to run an applet.
  • Executing the Applet within Java-compatible web browser.
  • Using an Applet viewer, such as the standard tool, applet viewer. An applet viewer executes your applet in a window
For executing an Applet in an web browser, create short HTML file in the same directory. Inside body tag of the file, include the following code. (applet tag loads the Applet class)
< applet code = "MyApplet" width=400 height=400 >
< /applet >
< APPLET
    [CODEBASE = codebaseURL]
    CODE = appletFile 
    [ALT = alternateText]
    [NAME = appletInstanceName]
    WIDTH = pixels
    HEIGHT = pixels 
    [ALIGN = alignment] 
    [VSPACE = pixels]
    [HSPACE = pixels]
>
[< PARAM NAME = appletParameter1 VALUE = value >]
[< PARAM NAME = appletParameter2 VALUE = value >]
. . .
[alternateHTML]
</APPLET>

Run the HTML file

running applet inside browser

Running Applet using Applet Viewer

To execute an Applet with an applet viewer, write short HTML file as discussed above. If name it as run.htm, then the following command will run your applet program.
f:/>appletviewer run.htm
running applet using applet viewer

No comments:

Post a Comment