Applet class
Java Applet is a special type of small Java program embedded in the webpage to generate dynamic content .
Applet Architecture
We know that java provides console based programming language environment and window based programming environment. An applet is a window based programming environment. Java applets are essentially java window programs that can run within a web page.Applete programs are java classes that extend that java.applet.Applet class and are enabaled by reference with HTML page.
The Applet and there class files are distribute through standard HTTP request and therefore can be sent across firewall with the web page data. Applete code is referenced automatically each time the user revisit the hosting website.
APPLET SKELETON
Most applets override these four methods. These four methods forms Applet lifecycle.
init() : init() is the first method to be called. This is where variable are initialized. This method is called only once during the runtime of applet.
start() : start() method is called after init(). This method is called to restart an applet after it has been stopped.
stop() : stop() method is called to suspend thread that does not need to run when applet is not visible.
destroy() : destroy() method is called when your applet needs to be removed completely from memory.
Servlet Life Cycle Methods
There are three life cycle methods of a Servlet :
- init()
- service()
- destroy()
Servlet Life Cycle:
Servlet life cycle can be defined as the stages through which the servlet passes from its creation to its destruction.
The servlet life cycle consists these stages:
- Servlet is borned
- Servlet is initialized
- Servlet is ready to service
- Servlet is servicing
- Servlet is not ready to service
- Servlet is destroyed
- setForeground() and setBachground()methods
setForeground() is used to set the foreground colour i.e the colour in which text is shown. The background colour can be changed to any colour by setBackground() BUT no matter what colour given inside setForegorund() the text is always black.
Which method is used to show status in applet?
Applets display status lines with the showStatus method, inherited in the JApplet class from the Applet class
HTML Applet tag
The HTML <applet> tag specifies an applet. It is used for embedding a Java applet within an HTML document.
How to embed a Java applet in HTML?
To run an applet in a browser or in the JDK Applet Viewer, the applet needs to be added to an HTML page, using the <APPLET> tag. You then specify the URL of the HTML page to your browser or the Applet Viewer.
What is meant by getCodeBase() and getDocumentBase() method?
- The getCodebase() method is also commonly used to establish a path to other files or folders that are in the same location as the class being run.
- The getDocumentBase() method is used to return the URL of the directory in which the document is resides.
How parameters are passed to an applet in Java?
To pass the parameters to the Applet we need to use the param attribute of <applet> tag. To retrieve a parameter's value, we need to use the getParameter() method of Applet class.
Post a Comment
0 Comments