Java Programming Chapter II
Java Programming Chapter II
Java Programming Chapter II
An applet is a small java program that are not stand-alone programs. Instead, they run
within either a web browser or an applet viewer.
Java can work within the World Wide Web of computers via browsers, such as Netscape and
Internet Explorer, google chrome etc. Applets are usually run from web browsers.
The JVM is able to run a Java program for the particular computer on which it is running.
An applet is embedded in an HTML page using the APPLET or OBJECT tag and hosted on a
web server.
Applets provide sound, graphics and animation in various forms and formats for web pages.
Overview of Applet cont…
4
Applets are used to make the website more dynamic and entertaining, also used in
games, gaming consoles, commercial websites, learning tools and many more.
init(): This method is intended for whatever initialization is needed for your applet. It is
called after the param tags inside the applet tag have been processed.
start(): This method is automatically called after the browser calls the init() method. It is
also called whenever the user returns to the page containing the applet after having gone
off to other pages.
stop(): This method is automatically called when the user moves off the page on which
the applet sits. It can, therefore, be called repeatedly in the same applet.
destroy(): This method is only called when the browser shuts down normally. Because
applets are meant to live on an HTML page, you should not normally leave resources
behind after a user leaves the page that contains the applet.
7
paint(): is invoked immediately after the start() method, and also any time the applet
needs to repaint itself in the browser. The paint() method is actually inherited from the
java.awt
There many types of web applications and numerous ways in which applets may be
applied.
Java Applets Vs Java Application
8
Java Applets Example
9 import java.applet.*;
import java.awt.*;
public class HelloWorldApplet extends Applet {
public void paint (Graphics g) {
g.drawString ("Hello World This is First Java Applet Program", 10, 50); } }