{"id":81,"date":"2018-07-10T11:26:30","date_gmt":"2018-07-10T11:26:30","guid":{"rendered":"http:\/\/itp16.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=81"},"modified":"2019-05-15T07:14:26","modified_gmt":"2019-05-15T07:14:26","slug":"applet-life-cycle","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/chapter\/applet-life-cycle\/","title":{"rendered":"APPLET LIFE CYCLE"},"content":{"raw":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/qv-Paoq0DVE\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n<div style=\"text-align: justify;\">\r\n\r\n&nbsp;\r\n\r\n<strong>Whatis an Applet?<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Applet is a Panel (inherits from Panel), which can be embedded in a webpage (HTML). What are the additional features of Applet compared to a Panel. It has the capability of interacting with the Browser, and has a life cycle defined by the Browser, when it is viewed in a web page on the browser. The life cycle defined by the help of methods invoked by the browser.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">For applet to working a browser, the browser must have JVM, the JVM needs to be started before the Applet can be used. When is the JVM started? It is normally started with the help of method main(). In the case of Browser the main is already started by the browser, before the web page is loaded. The browser has its own Java application, which it uses to manage the Java objects like Applet.<\/p>\r\n&nbsp;\r\n<p class=\"hanging-indent\"><strong>Browser as a Container for the Applet<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let\u2019s look at the sequence of events within the browser. Firstly, the JVM is already started within the browser with the help of some main method. When a web page is loaded which contains at least one tag for an Applet, then the java application within the browser would first create an instance of \u201cAppletContext\u201d. ie. one instance of \u201cAppletContext\u201d would be created per html page, which contains one or more Applet tags. The java application would parse the data between the &lt;Applet.....&gt; and &lt;\/Applet&gt; tags and create an instance of \u201cAppletStub\u201d for each such applet tag in the page. This instance has all the information specified between the &lt;Applet...&gt; and the &lt;\/applet&gt; tags. In the applet tag one of the attributes is code, eg. &lt;applet code=\".....\"...&gt; some class name is specified. The class name specified should be the name of a class which extends the Applet class. The browser would now send a request to the server from where the web page was loaded to get the contents of the applet class specified in the code attribute. The applet class is stored on the server and needs to be downloaded to the client machine. After downloading the content of the class file the browser would now load the downloaded class and then create an instance of the class using its default constructor. The public default constructor must be available for the applet class. After creating the instance, the browser would invoke the first method on the instance.<\/p>\r\n\r\n<\/div>\r\n<p style=\"text-align: center;\"><strong>LIFE-CYCLE OF AN APPLET<\/strong><\/p>\r\n&nbsp;\r\n\r\n<img class=\"alignnone size-full wp-image-85\" src=\"http:\/\/itp16.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/21\/2018\/07\/M12Pic1-1.png\" alt=\"\" width=\"768\" height=\"492\" \/>\r\n\r\n&nbsp;\r\n<div>\r\n<p style=\"text-align: justify;\"><strong>which is the first method invoked on an instance of Applet ?<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Is it init()? no. The first method invoked on the instance of Applet is \u201cpublic final void setStub(AppletStub stub)\" This is the first method invoked on the instance of Applet and not init(). this method is a final method in the Applet class. The instance of AppletStub created by the browser corresponding to this applet tag is passed to the Applet instance. Also the AppletStub has a method<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">\u201cpublic AppletContext getAppletContext()\u201d<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">This method would return the \u201cAppletContext\u201d instance corresponding to the web page of this applet. The \u201cAppletContext\u201d instance can be used for interaction with the browser. The Applet instance can get the information mentioned between the &lt;applet...&gt; and &lt;\/applet&gt; tags with the help of methods of the \u201cAppletStub\u201d instance which is given to it in the \u201csetStub\u201d method. This \u201cappletstub\u201d instance is also used for getting access to the \u201cappletcontext\u201d instance for interacting with the browser. So after invocation of \u201csetstub\u201d the applet instance has the knowledge about the information in the applet tag (mainly the parameters) and the capability to interact with the browser.<\/p>\r\n&nbsp;\r\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong style=\"text-align: justify; font-size: 1em;\">The life-cycle of an Applet<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em; text-align: initial;\">It is after \u201csetStub\u201d that the \u201cinit\u201d method is invoked. The \u201cinit\u201d method in the applet class has a blank implementation and can be overridden by the sub class of applet to do any kind of initialization. The browser maintains the state of the applet instance as being active or inactive. The instance of applet is active when the web-page containing it is currently being shown. The browser then invokes the method \u201cstart()\u201d and puts the applet in the active state. if the applet is becoming inactive because it is not on an active page. then the browser would invoke the \u201cstop()\u201d method on the instance and puts it into inactive state. so start and stop methods may be invoked by the browser any number of times depending on the activity of the user. Finally when the web-page containing the applet is being destroyed, in the browser. Then the browser would call the method \u201cdestory()\u201d on the instance of applet to indicate to the applet that it is now going to be destoryed. so the life cycle of an applet starts with \u201csetStub()\u201d, followed by\u00a0 \u201cinit()\u201d\u00a0 followed\u00a0 by \u201cstart()\u201d\u00a0 and then depending on the\u00a0 user activity may call stop and start any no. of times. and ultimately the last method invoked is \u201cdestroy()\u201d.<\/span><\/p>\r\n\r\n<ul>\r\n \t<li style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public final void setStub(AppletStub stub)<\/span><\/li>\r\n \t<li style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public fina lvoid init()<\/span><\/li>\r\n \t<li style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public final void start()<\/span><\/li>\r\n \t<li style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public final void stop()<\/span><\/li>\r\n \t<li style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public final void destroy()<\/span><\/li>\r\n<\/ul>\r\n<strong style=\"text-align: initial; font-size: 1em;\">Applet Stub<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\"><span style=\"text-align: justify; font-size: 1em;\">In the \u201cjava.applet\u201d package there is one class and three interfaces. You have the applet class, and the three interfaces are \u201cAppletStub\u201d, \u201cAppletContext\u201d and \u201cAudioClip\u201d. The \u201cAppletStub\u201d has methods for getting the information from the applet tag.<\/span><\/p>\r\n\r\n<\/div>\r\n<div style=\"text-align: center;\">\r\n\r\nThe following is the listing of the methods from the \u201cAppletStub\u201d:-\r\n\r\n&nbsp;\r\n<table class=\"lines\" border=\"1px solid black\" width=\"548\" align=\"center\">\r\n<tbody>\r\n<tr style=\"height: 43px;\">\r\n<td style=\"width: 11.0625px; height: 43px;\">\uf0b7<\/td>\r\n<td style=\"width: 55.0625px; height: 43px;\">void<\/td>\r\n<td style=\"width: 421.063px; height: 43px;\">appletResize(int width, int height)<\/td>\r\n<td style=\"width: 281.063px; height: 43px;\">\/\/ invoked to set the size of the corresponding<\/td>\r\n<\/tr>\r\n<tr style=\"height: 58px;\">\r\n<td style=\"width: 11.0625px; height: 58px;\">\uf0b7<\/td>\r\n<td style=\"width: 55.0625px; height: 58px;\">String<\/td>\r\n<td style=\"width: 421.063px; height: 58px;\">&nbsp;\r\n\r\ngetParameter(String paramname)<\/td>\r\n<td style=\"width: 281.063px; height: 58px;\">\/\/ applet instance.\r\n\r\n\/\/ returns the value of the given parameter<\/td>\r\n<\/tr>\r\n<tr style=\"height: 43px;\">\r\n<td style=\"width: 11.0625px; height: 43px;\">\uf0b7<\/td>\r\n<td style=\"width: 55.0625px; height: 43px;\">URL<\/td>\r\n<td style=\"width: 421.063px; height: 43px;\">getCodebase()<\/td>\r\n<td style=\"width: 281.063px; height: 43px;\">\/\/ returns the URL from where the classes can be loaded<\/td>\r\n<\/tr>\r\n<tr style=\"height: 29px;\">\r\n<td style=\"width: 11.0625px; height: 29px;\">\uf0b7<\/td>\r\n<td style=\"width: 55.0625px; height: 29px;\">URL<\/td>\r\n<td style=\"width: 421.063px; height: 29px;\">getDocumentBase()<\/td>\r\n<td style=\"height: 29px; width: 281.063px;\">\/\/ returns the URL from where\u00a0 the web page was loaded.<\/td>\r\n<\/tr>\r\n<tr style=\"height: 14px;\">\r\n<td style=\"width: 11.0625px; height: 14px;\"><\/td>\r\n<td style=\"width: 55.0625px; height: 14px;\"><\/td>\r\n<td style=\"width: 421.063px; height: 14px;\">boolean isActive()<\/td>\r\n<td style=\"height: 14px; width: 281.063px;\">\/\/ gives the active state of the corresponding applet instance<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The \u201cappletResize()\u201d method may be invoked on the \u201cAppletStub\u201d instance when- ever the associated Applet instance wants to be resized. The \u201cgetParameter()\u201d method can be used to get the value of the parameter which is specified in the applet tag. The \u201cgetCodeBase()\u201d method returns the URL from where the classes are loaded for this applet. The \u201cgetDocumentBase()\u201d method returns the URL from where the document (HTML page) has been loaded. The active state of the applet can be found using the \u201cisActive()\u201d method.<\/p>\r\n&nbsp;\r\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong>Applet Tag<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The Applet tag has attributes like code, width, height, codebase, archive, name and some other attributes related to the positioning of the applet within the browser. The code attribute is used for specifying the name of the applet class which should be loaded from the server. Width and height specify the dimensions of the applet instance within the browser. When a applet class is loaded from the server, during the execution of any of the methods in the applet, it may refer to some user- defined classes which are not part of the jdk. in such a case these user-defined classes also needs to be loaded. loading of user-defined classes would be done from the codebase mentioned in the tag. The codebase tag should refer to the directory on the server where all the classes are kept, including the applet class. The archive tag can be used to mention the java archive file on the server which contains all the classes. ie. If you have a jar file which contains all the class files, then it may be mentioned in the applet tag. If archive is mentioned in the tag then the browser would download the entire jar file first on the local machine and then load the classes locally instead of loading the classes over the network. The name tag is used to assign an identification to the applet instance. when it is created. The \u201cAppletContext\u201d instance keeps track of all the applet instances which are created in the browser on a single web page.<\/p>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify;\"><strong>In Summary:<\/strong><\/p>\r\n\r\n<ul style=\"text-align: justify;\">\r\n \t<li>Applet is a special type of Panel, which can be embedded on a Web page by a browser. It provides a set of life-cycle methods which are invoked by the browser.<\/li>\r\n \t<li>The browser always uses instances of some implementation of \u201cAppletContext\u201d and \u201cAppletStub\u201d along with the instances of Applet. For each Web page, there would be an instance of \u201cAppletContext\u201d created and for each Applet used in a page there would be a corresponding instance of \u201cAppletStub\u201d created in the browser\u2019s JVM.<\/li>\r\n \t<li>The methods which are invoked by the browser on the instance of Applet are \u201csetStub()\u201d, \u201cinit()\u201d, \u201cstart()\u201d, \u201cstop()\u201d and \u201cdestroy()\u201d. These methods form the life cycle of the Applet. \u201csetStub()\u201d is a final method and is the first method invoked on the applet. This is used to initialize the applet instance with its corresponding \u201cAppletStub\u201d. These \u201cAppletStub\u201d is making the \u201cAppletContext\u201d and parameter information available to the Applet. The instance of \u201cAppletContext\u201d enables the interaction of Applet with the browser. The other four life-cycle methods have a blank implementation and can be overridden by the applet developer.<\/li>\r\n<\/ul>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The \u201cinit()\u201d method is invoked only once initially after the invocation of the \u201csetStub()\u201d method. It is then followed by invocations of \u201cstart()\u201d and \u201cstop()\u201d based on when the applet is becoming active and when it is becoming inactive. The applet is active when it is visible, and inactive when it is not visible on the page. The \u201cstart()\u201d method is invoked to indicate that the applet\u2019s state has changed to active, and \u201cstop()\u201d method is invoked to indicate that the applet\u2019s state has changed to inactive. Finally when the applet is no longer required (when the user moves to another Web page), the applet\u2019s \u201cdestroy()\u201d method is invoked.<\/p>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on APPLET LIFE CYCLE<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/qv-Paoq0DVE\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<div><strong>Suggested Reading:<\/strong><\/div>\r\n<ol>\r\n \t<li>Core Java Volume 2 by Cay Horstmann &amp; Gary Cornell, Ninth Edition, Pearson Education.<\/li>\r\n \t<li>The class of JAVA by Pravin Jain, Pearson Education.<\/li>\r\n \t<li>An Introduction to Programming with Java Applets by Elizabeth S. Boese<\/li>\r\n \t<li>https:\/\/docs.oracle.com\/javase\/tutorial\/deployment\/applet\/index.html<\/li>\r\n<\/ol>","rendered":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/qv-Paoq0DVE\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<div style=\"text-align: justify;\">\n<p>&nbsp;<\/p>\n<p><strong>Whatis an Applet?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Applet is a Panel (inherits from Panel), which can be embedded in a webpage (HTML). What are the additional features of Applet compared to a Panel. It has the capability of interacting with the Browser, and has a life cycle defined by the Browser, when it is viewed in a web page on the browser. The life cycle defined by the help of methods invoked by the browser.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">For applet to working a browser, the browser must have JVM, the JVM needs to be started before the Applet can be used. When is the JVM started? It is normally started with the help of method main(). In the case of Browser the main is already started by the browser, before the web page is loaded. The browser has its own Java application, which it uses to manage the Java objects like Applet.<\/p>\n<p>&nbsp;<\/p>\n<p class=\"hanging-indent\"><strong>Browser as a Container for the Applet<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let\u2019s look at the sequence of events within the browser. Firstly, the JVM is already started within the browser with the help of some main method. When a web page is loaded which contains at least one tag for an Applet, then the java application within the browser would first create an instance of \u201cAppletContext\u201d. ie. one instance of \u201cAppletContext\u201d would be created per html page, which contains one or more Applet tags. The java application would parse the data between the &lt;Applet&#8230;..&gt; and &lt;\/Applet&gt; tags and create an instance of \u201cAppletStub\u201d for each such applet tag in the page. This instance has all the information specified between the &lt;Applet&#8230;&gt; and the &lt;\/applet&gt; tags. In the applet tag one of the attributes is code, eg. &lt;applet code=&#8221;&#8230;..&#8221;&#8230;&gt; some class name is specified. The class name specified should be the name of a class which extends the Applet class. The browser would now send a request to the server from where the web page was loaded to get the contents of the applet class specified in the code attribute. The applet class is stored on the server and needs to be downloaded to the client machine. After downloading the content of the class file the browser would now load the downloaded class and then create an instance of the class using its default constructor. The public default constructor must be available for the applet class. After creating the instance, the browser would invoke the first method on the instance.<\/p>\n<\/div>\n<p style=\"text-align: center;\"><strong>LIFE-CYCLE OF AN APPLET<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-85\" src=\"http:\/\/itp16.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/21\/2018\/07\/M12Pic1-1.png\" alt=\"\" width=\"768\" height=\"492\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-content\/uploads\/sites\/21\/2018\/07\/M12Pic1-1.png 768w, https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-content\/uploads\/sites\/21\/2018\/07\/M12Pic1-1-300x192.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-content\/uploads\/sites\/21\/2018\/07\/M12Pic1-1-65x42.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-content\/uploads\/sites\/21\/2018\/07\/M12Pic1-1-225x144.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-content\/uploads\/sites\/21\/2018\/07\/M12Pic1-1-350x224.png 350w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div>\n<p style=\"text-align: justify;\"><strong>which is the first method invoked on an instance of Applet ?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Is it init()? no. The first method invoked on the instance of Applet is \u201cpublic final void setStub(AppletStub stub)&#8221; This is the first method invoked on the instance of Applet and not init(). this method is a final method in the Applet class. The instance of AppletStub created by the browser corresponding to this applet tag is passed to the Applet instance. Also the AppletStub has a method<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">\u201cpublic AppletContext getAppletContext()\u201d<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">This method would return the \u201cAppletContext\u201d instance corresponding to the web page of this applet. The \u201cAppletContext\u201d instance can be used for interaction with the browser. The Applet instance can get the information mentioned between the &lt;applet&#8230;&gt; and &lt;\/applet&gt; tags with the help of methods of the \u201cAppletStub\u201d instance which is given to it in the \u201csetStub\u201d method. This \u201cappletstub\u201d instance is also used for getting access to the \u201cappletcontext\u201d instance for interacting with the browser. So after invocation of \u201csetstub\u201d the applet instance has the knowledge about the information in the applet tag (mainly the parameters) and the capability to interact with the browser.<\/p>\n<p>&nbsp;<\/p>\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong style=\"text-align: justify; font-size: 1em;\">The life-cycle of an Applet<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-size: 1em; text-align: initial;\">It is after \u201csetStub\u201d that the \u201cinit\u201d method is invoked. The \u201cinit\u201d method in the applet class has a blank implementation and can be overridden by the sub class of applet to do any kind of initialization. The browser maintains the state of the applet instance as being active or inactive. The instance of applet is active when the web-page containing it is currently being shown. The browser then invokes the method \u201cstart()\u201d and puts the applet in the active state. if the applet is becoming inactive because it is not on an active page. then the browser would invoke the \u201cstop()\u201d method on the instance and puts it into inactive state. so start and stop methods may be invoked by the browser any number of times depending on the activity of the user. Finally when the web-page containing the applet is being destroyed, in the browser. Then the browser would call the method \u201cdestory()\u201d on the instance of applet to indicate to the applet that it is now going to be destoryed. so the life cycle of an applet starts with \u201csetStub()\u201d, followed by\u00a0 \u201cinit()\u201d\u00a0 followed\u00a0 by \u201cstart()\u201d\u00a0 and then depending on the\u00a0 user activity may call stop and start any no. of times. and ultimately the last method invoked is \u201cdestroy()\u201d.<\/span><\/p>\n<ul>\n<li style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public final void setStub(AppletStub stub)<\/span><\/li>\n<li style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public fina lvoid init()<\/span><\/li>\n<li style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public final void start()<\/span><\/li>\n<li style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public final void stop()<\/span><\/li>\n<li style=\"text-align: justify;\"><span style=\"text-align: initial; font-size: 1em;\">public final void destroy()<\/span><\/li>\n<\/ul>\n<p><strong style=\"text-align: initial; font-size: 1em;\">Applet Stub<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\"><span style=\"text-align: justify; font-size: 1em;\">In the \u201cjava.applet\u201d package there is one class and three interfaces. You have the applet class, and the three interfaces are \u201cAppletStub\u201d, \u201cAppletContext\u201d and \u201cAudioClip\u201d. The \u201cAppletStub\u201d has methods for getting the information from the applet tag.<\/span><\/p>\n<\/div>\n<div style=\"text-align: center;\">\n<p>The following is the listing of the methods from the \u201cAppletStub\u201d:-<\/p>\n<p>&nbsp;<\/p>\n<table class=\"lines\" style=\"width: 548px; margin: auto;\">\n<tbody>\n<tr style=\"height: 43px;\">\n<td style=\"width: 11.0625px; height: 43px;\">\uf0b7<\/td>\n<td style=\"width: 55.0625px; height: 43px;\">void<\/td>\n<td style=\"width: 421.063px; height: 43px;\">appletResize(int width, int height)<\/td>\n<td style=\"width: 281.063px; height: 43px;\">\/\/ invoked to set the size of the corresponding<\/td>\n<\/tr>\n<tr style=\"height: 58px;\">\n<td style=\"width: 11.0625px; height: 58px;\">\uf0b7<\/td>\n<td style=\"width: 55.0625px; height: 58px;\">String<\/td>\n<td style=\"width: 421.063px; height: 58px;\">&nbsp;<\/p>\n<p>getParameter(String paramname)<\/td>\n<td style=\"width: 281.063px; height: 58px;\">\/\/ applet instance.<\/p>\n<p>\/\/ returns the value of the given parameter<\/td>\n<\/tr>\n<tr style=\"height: 43px;\">\n<td style=\"width: 11.0625px; height: 43px;\">\uf0b7<\/td>\n<td style=\"width: 55.0625px; height: 43px;\">URL<\/td>\n<td style=\"width: 421.063px; height: 43px;\">getCodebase()<\/td>\n<td style=\"width: 281.063px; height: 43px;\">\/\/ returns the URL from where the classes can be loaded<\/td>\n<\/tr>\n<tr style=\"height: 29px;\">\n<td style=\"width: 11.0625px; height: 29px;\">\uf0b7<\/td>\n<td style=\"width: 55.0625px; height: 29px;\">URL<\/td>\n<td style=\"width: 421.063px; height: 29px;\">getDocumentBase()<\/td>\n<td style=\"height: 29px; width: 281.063px;\">\/\/ returns the URL from where\u00a0 the web page was loaded.<\/td>\n<\/tr>\n<tr style=\"height: 14px;\">\n<td style=\"width: 11.0625px; height: 14px;\"><\/td>\n<td style=\"width: 55.0625px; height: 14px;\"><\/td>\n<td style=\"width: 421.063px; height: 14px;\">boolean isActive()<\/td>\n<td style=\"height: 14px; width: 281.063px;\">\/\/ gives the active state of the corresponding applet instance<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The \u201cappletResize()\u201d method may be invoked on the \u201cAppletStub\u201d instance when- ever the associated Applet instance wants to be resized. The \u201cgetParameter()\u201d method can be used to get the value of the parameter which is specified in the applet tag. The \u201cgetCodeBase()\u201d method returns the URL from where the classes are loaded for this applet. The \u201cgetDocumentBase()\u201d method returns the URL from where the document (HTML page) has been loaded. The active state of the applet can be found using the \u201cisActive()\u201d method.<\/p>\n<p>&nbsp;<\/p>\n<p class=\"hanging-indent\" style=\"text-align: justify;\"><strong>Applet Tag<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The Applet tag has attributes like code, width, height, codebase, archive, name and some other attributes related to the positioning of the applet within the browser. The code attribute is used for specifying the name of the applet class which should be loaded from the server. Width and height specify the dimensions of the applet instance within the browser. When a applet class is loaded from the server, during the execution of any of the methods in the applet, it may refer to some user- defined classes which are not part of the jdk. in such a case these user-defined classes also needs to be loaded. loading of user-defined classes would be done from the codebase mentioned in the tag. The codebase tag should refer to the directory on the server where all the classes are kept, including the applet class. The archive tag can be used to mention the java archive file on the server which contains all the classes. ie. If you have a jar file which contains all the class files, then it may be mentioned in the applet tag. If archive is mentioned in the tag then the browser would download the entire jar file first on the local machine and then load the classes locally instead of loading the classes over the network. The name tag is used to assign an identification to the applet instance. when it is created. The \u201cAppletContext\u201d instance keeps track of all the applet instances which are created in the browser on a single web page.<\/p>\n<\/div>\n<p style=\"text-align: justify;\"><strong>In Summary:<\/strong><\/p>\n<ul style=\"text-align: justify;\">\n<li>Applet is a special type of Panel, which can be embedded on a Web page by a browser. It provides a set of life-cycle methods which are invoked by the browser.<\/li>\n<li>The browser always uses instances of some implementation of \u201cAppletContext\u201d and \u201cAppletStub\u201d along with the instances of Applet. For each Web page, there would be an instance of \u201cAppletContext\u201d created and for each Applet used in a page there would be a corresponding instance of \u201cAppletStub\u201d created in the browser\u2019s JVM.<\/li>\n<li>The methods which are invoked by the browser on the instance of Applet are \u201csetStub()\u201d, \u201cinit()\u201d, \u201cstart()\u201d, \u201cstop()\u201d and \u201cdestroy()\u201d. These methods form the life cycle of the Applet. \u201csetStub()\u201d is a final method and is the first method invoked on the applet. This is used to initialize the applet instance with its corresponding \u201cAppletStub\u201d. These \u201cAppletStub\u201d is making the \u201cAppletContext\u201d and parameter information available to the Applet. The instance of \u201cAppletContext\u201d enables the interaction of Applet with the browser. The other four life-cycle methods have a blank implementation and can be overridden by the applet developer.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The \u201cinit()\u201d method is invoked only once initially after the invocation of the \u201csetStub()\u201d method. It is then followed by invocations of \u201cstart()\u201d and \u201cstop()\u201d based on when the applet is becoming active and when it is becoming inactive. The applet is active when it is visible, and inactive when it is not visible on the page. The \u201cstart()\u201d method is invoked to indicate that the applet\u2019s state has changed to active, and \u201cstop()\u201d method is invoked to indicate that the applet\u2019s state has changed to inactive. Finally when the applet is no longer required (when the user moves to another Web page), the applet\u2019s \u201cdestroy()\u201d method is invoked.<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on APPLET LIFE CYCLE<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/qv-Paoq0DVE\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div><strong>Suggested Reading:<\/strong><\/div>\n<ol>\n<li>Core Java Volume 2 by Cay Horstmann &amp; Gary Cornell, Ninth Edition, Pearson Education.<\/li>\n<li>The class of JAVA by Pravin Jain, Pearson Education.<\/li>\n<li>An Introduction to Programming with Java Applets by Elizabeth S. Boese<\/li>\n<li>https:\/\/docs.oracle.com\/javase\/tutorial\/deployment\/applet\/index.html<\/li>\n<\/ol>\n","protected":false},"author":4,"menu_order":12,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["mr-pravin-jain"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-81","chapter","type-chapter","status-publish","hentry","contributor-mr-pravin-jain"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapters\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":12,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapters\/81\/revisions"}],"predecessor-version":[{"id":399,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapters\/81\/revisions\/399"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapters\/81\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/pressbooks\/v2\/chapter-type?post=81"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/wp\/v2\/contributor?post=81"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp16\/wp-json\/wp\/v2\/license?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}