Hi there,

I am Rohan!

""""✰I am always blown away to see thought leaders like Rohan with ambition, having a positive impact on the world!"✰ Michael Walmsley, CEO and founder of CodeAvengers.
Join Rohan Chaubey on

Applet And Graphics Programming In Java! - Series Finale!

Here is the links to the previous blogs : 

1. Fundamentals Of Java Programming Language - Click here!
2. White Spaces, Data Types, Variables and Array Of Objects - Click here!
3. Method Overriding, Constructor Overloading, Scanner class! - Click here!
4. Inheritance, Interfaces, Abstract Classes and Access Specifiers! - Click here!
5. Packages In Java! - Click here!
6. Exception Handling In Java! - Click here!
7. Multithreading In Java! - Click here!
8. Applet And Graphics Programming In Java! - Click here!

What is Applet?

An applet is a small program which can displayed on a web page. It is dynamic and Interactive.
Before we start writing an applet program, we need to import .applet and .awt package.
When we declare our applet class name we need to extend pre-defined Applet class which is defined in java.applet.package.

Applet class hierarchy
Applet class hierarchy
An applet life cycle includes 5 states and 5 methods...

1. Initialization or Born state = init() method.
2. Running state = Start() method.
3. Display state = Paint() method. (Not Considered).
4. Idle state = Stop() method.
5. Destroyed or Dead state = Destroy() method.

Applet life cycle
Applet life cycle
We can view an applet by using a java enabled web browser like HotJava or appletviewer. Nowadays, almost all the web browsers support applets.

Following is a sample code to run an applet :

Following example demonstrates how to create a basic Applet by extending Applet Class.You will need to embed  HTML code to run this program.

import java.applet.*;
import java.awt.*;

public class Main extends Applet{
   public void paint(Graphics g){
      g.drawString("Learnign Java With TeamSR.",40,20);
 // Now call the class in your HTML code as follows:
<APPLET CODE="Main.class" WIDTH="800" HEIGHT="500"> </APPLET

We can draw different shapes using the graphics class and applet class. Shapes like oval, circle, rectangle, polygon,etc. can be drawn using method like drawOval, drawPoly, drawRect, etc.

To get the programs on graphics Click here! 

ABOUTRohan Chaubey

Rohan Chaubey is the founder of “Be Rohanlicious” – a blog that teaches you to be smart with social media, blogging and programming.

Rohan is on a mission to help all the enthusiastic souls like you, who want to “make it to the next level” and stand out of the crowd.

His e-book “Make People Want You” is releasing soon. Allow him to inject awesomeness in your life by signing up to his list here.