Introduction to Applet programming
An Applet is a small internet-based program that has the Graphical user interface ( GUI), written in the JAVA programming language.
Applets are designed to run inside a web browser or in Applet viewer to facilitate the user to animate the graphics, play sound, and design the GUI components such as text box, bottom, and radio button. When Applet arrives on the client, it has limited access to resources, so that it can produce arbitrary multimedia user interface and run complex computation without introducing the risk of viruses or breaching data integrity.
To create an Applet , we extend the JAVA.applet.
AppletΩ class and by overriding the methods of java.awt Applet, new functionality can be placed into web pages.
Applets are compiled using javac compiler and it can be executed by using an Applet viewer or by embedding the class files in the HTML (Hyper Text markup language) file.
Applet vs Application
Applet as previously described, are the small programs while applications are larger programs.
Applets don't have the main method while in an application execution starts with the main method
Applets are designed just for handling the client site problems, while the Java applications are designed to work with the client as well as server.
Applications are designed to exits in a secure area. While the applets are typically used.
Applications are not too small to embed into a HTML page so that the user can view the application in your browser. On the other hand, Applet have the accessibility criteria of the resources.
Applet class
The Java.applet package is the smallest package in Java API (Application programming interface). The applets class is the only class in the package. The applets class has many methods that are used to display images, play audio files etc but it has no main () method. Some of them were explained below that give you the knowledge about Applets and their behavior.
Intt():
This method is used for whatever initializations are needed for your Applet. Applets can have default constructor, but it is better to perform all initializations in the unit method instead of the default constructor.
Start():
This method is automatically called after Java calls the unit method. If this method is overwritten, code that visit the browser page that contains this Applet.
Stop():
This method is automatically called when the user moves off the page where the applets. This Applet doesn't perform animation, play audio files, or perform calculations in a thread, you don't usually need to use this method.
Destroy():
Java calls this method when the browser stuts down.
Advantages of Applet
Following are the advantages of a Java Applet:
The most important features of an Applet is, it is truly platform independent so there is no need of making any changes in the code for different platform i.e. it is simple to make it work on Linux, windows and Mac OS i.e. to make it cross platform.
The same Applet can work on "all" installed version of Java at the same time, rather than just the latest plug-in version only.
It can move the work from the server to the client, making a web solution more scalable with the number of users/clients.
The applets naturally supports the changing user state like figure positions on the classboard.
Applet improves with use: after a first Applet is run, the JVM is already running and starts quickly.
Applets can be used to provide dynamic user-interfaces and a variety of graphical effects for web pages.
Applet Lifecycle
Every Java Applet inherits a set of default behavior from the applets class. As a result, when an Applet is loaded it undergoes a series of changes in it's state.
States in Applet Lifecycle.
Born or lnitialization state:
An Applets begins it's life when the web browser loads it's classes and calls it's init() method. This method is called exactly once in Applets lifecycle and is used to read Applet parameters. This, in the unit() method one should provide initialization code such as the initialization of variables.
e.g. public void init()
{
//Initialization
}
2. Running state
Once the initialization is complete, the web browser will call the start() method in the applets. This method must called atleast once in the applets lifecycle as the start () method can also be called if the applets is in Stopped|| state. At this point.
e.g public void start()
{
//Code
}
3. Stopped state
The web browser will call the Applets stop() method, if the user moves to another web page while the applets was executing. So explore the web some more. They stop() method is calledatleast once in Applets lifecycle.
e.g. public void stop()
{
//Code
}
4. Dead State
Finally, if the user decides to quit the web browser, the web browser will free up system resources by killing the applets before if closes. To do so, it will call the apples destroy () method. One can overtired destroy () to perform one- time task upon program completion. For example, cleaning up threads which where started in the unit() method.
e.g. public void destroy ()
{
//Code
}
NOTE: If the user returns to the applets , the web browser will simply call the applet's start() Method again and the user will be back into the program.
5. Display state
Applet move to the display state whenever it has to perform the output operations on the screen. This happens immediately after the Applet enters into running state. The paint() method is called to accomplish this task.
e.g. public void paint (Graphics g)
{
//Display statements
}
One can show lifecycle of an Applet Graphically as follows:
THE REVIEW ON THIS TOPIC WILL BE UPLOAD LOADED WHEN WE ARE DONE WITH OUR FINDINGS AND CODING TO GIVE U THE BEST RESULTS.
Big
thanks to all my theme members and all my co programmer worldwide, I
love u all and thanks for making Life more easy for all my kind
INSIDEIMT.ORG.NG LOVE U ALL.
More thanks to you all that find our most interesting and important by Reading all our post and visiting our blog day by day, which through it we are incoraged to invest and do more research to give you the bet
0 Comments