What is an applet?
* a small Java program that can be inserted into a web page and
run by loading that page in a browser.
+ An applet, like any application program, can do many things.
+ Itcan perform arithmetic operations, display graphics, play
sounds, accept user Ee, create animation, and so on.
+ This is the feature of Java that i 13 primarily HanansDle for its
initial i popularity:
Applet execution by a browser
L) request HTML page
/ <
na, |
a
Chana |
/ | 6) eotcute
( Java yeplet
PL {GI Sat
TH Reference
to Java
yy peeae
mM.Applet classes in Java
+ Implementation
~ a top-level container, like a Frame. *
— behaves more like a Panel.
— It does not contain a title bar, menu bar, or border.
— This is why you don’t see these items when an applet is run
inside a’ browser. Wi
HAH
5 — When you run an applet us
‘ viewer patel thet
- -~ java.apple App.
ree or
i)
How Applets Differ
a
* Although both the A et stand-alone i
applications are Java programs, there are certain i
restrictions are impdsed on Applets, due to security
concerns:
~ Applets don’t use the main() method, but when they are loaded,
“automatically call certain methods (init, start, paint, stop,
destroy),
~ They are embedded inside a web page and executed in browsers.
~ Takes input through Graphical User Interface(GUI).
— They cannot read from or write to the files on local computer.
They cannat run any programs from the local computer,
— They are restricted from using libraries from other languages.
* The aboye restrictions ensures that an Applet gannot
do any damage to the local system
Building Applet Code: An Example
import java.awt.*;
impart ict. AppletBuilding Applet Code: An Example
import java.awt.*;
import java.applet. Applet;
public class SimpleApplet extends Applet {
public void paint(Graphics g) { t
g.drawString ("A Simple Applet",20, 20);
}
}
> Begins with two import classes. -
_ ¥javaawi" required for GUI
> java.applet.* -- every ap
> of Applet
> The class should start wit
from outside.
+ ‘An applet begins a when the name of its
class is passed to an applet viewer or to a network
browser.
* Compile the applet in the same way that we have
been compiling programs.
+ Running an applet involves a different process.
Running an Applet
1. Using web browserRunning an Applet
1. Using web browser
2. Using appletviewer
+ To execute an applet
short HTML file that c
apelet
1 a web browser, you need to write a
sa tag veer) that loads the
HTML file that pate