over 9 years ago
APPLET
Applet are the client side web based program run on web browser. Applet implements the functionality of the clients.Dynamic and interactive programs runs inside a web page with a displayed Java capable browser.We don't have constructor in applet. Applet is invoked either through browser or through applet viewer utility provided by the JDK.
APPLET LIFE CYCLE:
There are four methods in the Applet class which gives you the framework on which you build any applet:
1) init: This method is called once during the entire life cycle of an applet.This method is used for the initialization of your applet.
2)start: After the browser calls the init method start method is automatically called . It is also called whenever the user get back to the page containing the applet after having gone off to other pages.This method basically called to start the applet.
3)stop:With this method the browser moves off applet page.
4)destroy: When the browser shuts down normally then this method is called . Because the applets is meant to live on an HTML page, you cannot normally leave resources behind after a user leaves the page that contains the applet.
5)paint: This method is invoked immediately after the start() method, and also any time if the applet wants to repaint itself in the browser. It minimizes or refresh figures or images on the applet window.
- A HELLO WORLD APPLET:
- import java.applet.*;
- import java.awt.*;
- public class HWApplet extends Applet
- {
- public void paint (Graphics g)
- {
- g.drawString ("Hello World", 25, 50);
- }
- }
A HELLO WORLD APPLET: import java.applet.*; import java.awt.*; public class HWApplet extends Applet { public void paint (Graphics g) { g.drawString ("Hello World", 25, 50); } }
These statements bring the classes into the scope of our applet class:
The Java compiler would not recognize the classes Applet and Graphics, which the applet class refers to without these import statements.
THE APPLET CLASS: The java.applet.Applet class is an extension of every applet . These include methods that do the following:
An Applet class provides the user with the default implementations of each of these methods. Those implementations can be overridden if necessary.
The "Hello World" applet is complete as it stands. The only method overridden is the paint method.
0 Comment(s)