A program blog designed to be executes within another page or application. Applets cannot be run or executed directly from the operating system unlike an application. Because of the growing popularity of object linking and embedding (OLE), applets are becoming more prevalent. A well-designed applet would be runs from many different website.
Web browsers, which are equipped with JVM (Java virtual machines), can interpret applets from Web servers. Because applets are cross-platform compatible , small in files size, and highly secure, they are reliable for small Internet website or applications run from a browser.
Advantage of Applet
There are lot of advantages of applet i.e. :
• less response time because It works at client side.
• It can be executed on different operating system Linux, Windows, Mac Os etc. by help of browsers.
Drawback of Applet
• To execute applet plugin is required at client side browser.
Hierarchy of Applet
In the above diagram, Applet class extends Panel. Panel class extends Container which is the subclass of Component.
Java Applet of Lifecycle
Applet of Lifecycle methods:
The java.applet.Applet class 4 life cycle methods and java.awt.Component class provides 1 life cycle methods for an applet.
For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle methods of applet.
1. public void init() method : This method is used to initialized the Applet. It is invoked only once of applet life cycle.
2. public void start() method : This method is run after the init() method or browser is maximized / open. It is used to start / run the Applet.
3. public void stop() method : This method is used to stop the Applet. It is invoked when Applet is stop working or browser is minimized / close.
4. public void destroy() method : This method is used to destroy the Applet. It is invoked only once in applet life cycle.
The Component class provides 1 life cycle method of applet.
1. public void paint(Graphics g): This method is used to paint the Applet. It provides Graphics class object are used for drawing arc, rectangle, oval, line, circle etc.
Responsible to manage the life cycle of an applet?
Java Plug-in software.
How to run an Applet?
There are two ways to run an applet
1. By html file.
2. By appletViewer tool (for testing purpose).