Java Applets: The HTML Page Must Tells The Browser
Java Applets: The HTML Page Must Tells The Browser
The browser then received the .class files from directory on the
user’s machine and runs the applet using JVM.
In Java,
Applet is simply a Java class that extends the java.appet class.
It is not part of AWT package
Create an HTML file that tells the browser which class file is to
load first and how to size the applet.
Before that,
We view the applet in a browser it is good to test it in appletviewer
part of JDK.
1. init: -
This method is used for initialization of our applet.
This method also used for adding user interface components.
Syntax:
public void init()
{
// code for
// Initialization
}
2. start: -
This method get called automatically after the browser calls
the init () method.
Resume an animation.
The code which we need to execute when user exits the browser, we
add it in this method.
The Java enabled browser will download all the applet code on
the web page and execute it immediately.
The applet playing in sandbox can not alter the users system.
Code: - This code gives the name of the applet’s class file.
This name is related to the codebase or relative to current page
if codebase is not specified.
code = “Pack.MyPackage.MyApplet.class”
OR
code = “Pack/MyPackage/MyApplet.class”
Align: -
It specifies the alignment of an applet in the browser or window.
Right: - It places the applet at right margin and text on the left of
an applet.
Top: - It places the top of an applet at the top of the current line.
Middle: - It places the middle of an applet with base line of the text in
current line.
Codebase: -
This attribute is used to specifying the location of class file.
Most commonly it is used to points to a subdirectory.
e.g.
If MyApp.class is located in subdirectory SubPack of current directory
then the attribute codebase has value…
Archive: -
This attribute lists the Java archive files containing classes and
other resources for the applet.
These files are fetched from the web server before the applet is
loaded.
Application Conversion to Applets: -
To convert Graphical Application into Applets…
Make an HTML page with the appropriate tag to load the applet tag.
Supply a subclass of the JApplet class. Make this class public, otherwise
applet can not be loaded.
Do not construct the frame window for the application. Our application
will be displayed in the browser.
Remove the code to close the window, because applet can’t be closed, it
terminates when the browser exits.
Remove the call to setTitle () method, because applet can’t have title bar.