What is an Applet in java?
- Applet is an special java program that runs on the client's machine's browser.
- Applets are used to generate dynamic contents on the web page.
Today Applets are replaced by the java's Servlet but remember one thing that Servlet are not on client side but they are server side whereas Applets are client side.
what is meant by server side and client side?
What are the advantages and disadvantages of Applets?
Advantage of Applet
There are many advantages of applet. They are as follows:
- It works at client side so less response time.
- Secured
- It can be executed by browsers running under many platforms, including Linux, Windows, Mac Os etc.
Drawback of Applet
Hierarchy of Applet
As displayed in the above diagram, Applet class extends Panel. Panel class extends Container which is the subclass of Component. |
Life cycle of Java Applet
- Applet is initialized.
- Applet is started.
- Applet is painted.
- Applet is stopped.
- Applet is destroyed.
Life cycle methods for Applet:
The java.applet.Applet class 4 life cycle methods and java.awt.Component class provides 1 life cycle methods for an applet.
java.applet.Applet class
For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle methods of applet.
- public void init(): is used to initialized the Applet. It is invoked only once.
- public void start(): is invoked after the init() method or browser is maximized. It is used to start the Applet.
- public void stop(): is used to stop the Applet. It is invoked when Applet is stop or browser is minimized.
- public void destroy(): is used to destroy the Applet. It is invoked only once.
java.awt.Component class
The Component class provides 1 life cycle method of applet.
- public void paint(Graphics g): is used to paint the Applet. It provides Graphics class object that can be used for drawing oval, rectangle, arc etc.
Who is responsible to manage the life cycle of an applet?
Java Plug-in software.
Remember Points:
- Applets do not contain the main() method in the program.
- The class in which you are creating an Applet should be public so that java plug in software can use it.
No comments:
Post a Comment