What Is JAVA Applet? How To Run Java Applet Program? - FindersAdda : Tutorials of Make Money, Computer or Internet

Sunday, 12 November 2017

What Is JAVA Applet? How To Run Java Applet Program?

An Applet is a web-based java application that enables us to write the functionality for a webpage.

An applet provides the stand-alone functionality i.e. the applet is created on machine. It can only be executed on the same machine. However, there are possibilities in which an applet can be executed on remote hosts.

Java applet program run inside the browser and works at client side.

The working of Applet is controlled by the various methods such as init(), start(), stop(), paint() and destroy().


Applet Life Cycle


  1. Applet is Initialized
  2. Applet is Started
  3. Applet is Painted
  4. Applet is stopped
  5. Applet is destroyed

Method For Applet


The below four method belongs to java.applet.Applet; class and paint() method belongs to java.awt.Component; class. 


public void init() : - The init() method serves as the constructor for the applet. It is the first method to be executed. Whenever, an applet is loaded into the memory. This method contains the basic initialization.

public void start() : - The start() method brings an Applet to the running state either from the New Born state or the idle state.

public void stop() : - The stop() method is used to temporary pause the running applet i.e it changes the state of an applet from running to idle.

public void destroy() : - The destroy() method terminates the applet i.e it transfer the state of an applet to along state.

public void paint() : - The paint() method is most important method in the life cycle in an Applet. As it is responsible for executing the functionality of an applet. This method accepts the graphics class object as its parameter and draws the information in the form of text and graphics from the applet area.
It indirectly calls the repaint() and update() method when the applet area is to be redrawn.


How to Run Java Applet Program?


To run java applet program, you must have installed java that means your computer should be java run time environment.

1. Write applet program in any text editor.

2. Save this program in your computer with .java extension

3. Open command prompt and type javac programname.java for compilation

4. If you want to run applet program by using HTML then skip 5th step

5. If your program is successfully compiled then type appletviewer programname.java for run applet program. 



You can run your java applet program by two methods. First by using HTML method and second by using appletviewer (for testing purpose). If you want to run java applet program in Browser then you have to need a plugin. I will write a post on how to set plugin in browser as soon as possible.







Compile and run the applet program

Applet output

I hope you liked this post so much. If you loved this post, Then, share with your friends and also give some suggestion that what should i improve in this post. Thank You So Much...... 

About Author

SUMIT KUMAR GUPTA
SUMIT KUMAR GUPTA

Author & Editor

Myself Sumit Kumar Gupta & 21 year's old person. I am a programmer and blogger. I spend much more time on programming and blogging and helps other programmers and bloggers.

0 comments:

Post a Comment

We are eager to see your comments.
Comment Rule :

1. Don't use any link in the comment box. If you have any problem related to link then contact me with the contact form.

2. Don't use the wrong word if you write the wrong word in comment box then it will get spam.