• Who is responsible to manage the life cycle of an applet? • How to perform animation in applet? • How to paint like paint brush in applet? • How to display digital clock in applet? • How to display analog clock in applet?
• How to communicate two applets? Hierarchy of Applet As displayed in the above diagram, Applet class extends Panel. Panel class extends Container which is the subclass of Component. Lifecycle of Java Applet • Applet is initialized. • Applet is started. • Applet is painted.
An applet is a Java program that runs in a Web browser. An applet can be a fully functional Java application because it has the entire Java API at its disposal. There are some important differences between an applet and a standalone Java application, including the following − An applet is a Java class that extends the java.applet.Applet class. Public class Applet extends java.awt.Panel. An applet is a small program that is intended not to be run on its own, but rather to be embedded inside another application.
• Applet is stopped. • Applet is destroyed.
Lifecycle 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. How to run an Applet? There are two ways to run an applet • By html file.
• By appletViewer tool (for testing purpose). Simple example of Applet by html file: To execute the applet by html file, create an applet and compile it.
After that create an html file and place the applet code in html file. Now click the html file.