An Applet is a window based java program that is used for internet applications. These can be run by using either web browser or with an applet viewer. There are two types of applets: Local applets and Remote applets.
Remote applets: Remote applets are developed by unknown persons and stored in remote computers. To run a remote applet internet connection is needed. At the run time the system searches the applet code in the internet and it is downloaded. To download a remote applet, we must give the address of the applet in HTML page.
Steps to create Applet:
The steps involved in creating an applet are,
Building applet code:
To build an applet code we are in need of the following two already existing base classes. They are
a) Applet and b) Graphics.
a) Applet class:
Applet class is available in the package java.applet . Important methods available in applet class are:
Init( ), start( ), stop( ), destroy( ),paint( ).
Init( ) method is used to initialize the variables. This is called only once during the run time of applet.
Syntax: void init()
Start() method is called by the browser after init() method is called. This helps to restart an applet after it has been stopped.
General form: void start( )
Stop() method is used to suspend the execution of an applet. Once stopped it can be restarted using the method start( ).
Syntax: void stop()
Destroy( ) method is used to remove the applet completely from the memory. Before calling destroy() we must call stop( ).
General form: void destroy( ).
Paint() method is used to display graphical applet output. This method has only one argument of type graphics. This can be called any number of times.
General form: void paint(Graphics obj)
b) Graphics class:
Graphics class is available in the package “java.awt”.This class is a must while building an applet. This class object is used an argument for the paint() method. This method is used to display graphical applet output with the help of the method drawstring() in the graphics class.