SlideShare a Scribd company logo
1 of 14
Java Applet
Chapter 7
Java Applets
• Overview of Java Applets
• Java Applets Vs Java Application
Java Applet
• Applet is a special type of program that is
embedded in the webpage to generate the
dynamic content. It runs inside the browser
and works at client side.
Advantage of Applet
• There are many advantages of applet. They are as
follows:
– It works at client side so less response time.
– Secured
– It can be executed by browsers running under many
platforms, including Linux, Windows, Mac OS etc.
Drawback of Applet
– Plug-in is required at client browser to execute applet.
Hierarchy of Applet
As displayed in this diagram, Applet class
extends Panel. Panel class extends Container
which is the subclass of Component.
Lifecycle of Java Applet
1. Applet is initialized.
2. Applet is started.
3. Applet is painted.
4. Applet is stopped.
5. Applet is destroyed.
Lifecycle methods for Applet
• The java.applet.Applet class 4 life cycle methods and
java.awt.Component class provides 1 life cycle methods for
an applet.
java.applet.Applet class
• For creating any applet java.applet.Applet class must be
inherited. It provides 4 life cycle methods of applet.
1. public void init(): is used to initialized the Applet. It is
invoked only once.
2. public void start(): is invoked after the init() method or
browser is maximized. It is used to start the Applet.
3. public void stop(): is used to stop the Applet. It is invoked
when Applet is stop or browser is minimized.
4. public void destroy(): is used to destroy the Applet. It is
invoked only once.
Cont…
java.awt.Component class
• The Component class provides 1 life cycle method
of applet.
1. public void paint(Graphics g): is used to paint
the Applet. It provides Graphics class object that
can be used for drawing oval, rectangle, arc etc.
• Who is responsible to manage the life cycle of an
applet?
Ans. Java Plug-in software
How to run an Applet?
• There are two ways to run an applet
1. By html file.
2. By appletViewer tool (for testing purpose).
Example
import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet{
public void paint(Graphics g){
g.drawString("welcome",150,150);
}
}
Displaying Graphics in Applet
Commonly used methods of Graphics class:
1. public abstract void drawString(String str, int x, int y): is used to
draw the specified string.
2. public void drawRect(int x, int y, int width, int height): draws a
rectangle with the specified width and height.
3. public abstract void fillRect(int x, int y, int width, int height): is
used to fill rectangle with the default color and specified width and
height.
4. public abstract void drawOval(int x, int y, int width, int height): is
used to draw oval with the specified width and height.
5. public abstract void fillOval(int x, int y, int width, int height): is
used to fill oval with the default color and specified width and
height.
Cont…
6. public abstract void drawLine(int x1, int y1, int x2, int y2): is used to
draw line between the points(x1, y1) and (x2, y2).
7. public abstract boolean drawImage(Image img, int x, int y,
ImageObserver observer): is used draw the specified image.
8. public abstract void drawArc(int x, int y, int width, int height, int
startAngle, int arcAngle): is used draw a circular or elliptical arc.
9. public abstract void fillArc(int x, int y, int width, int height, int
startAngle, int arcAngle): is used to fill a circular or elliptical arc.
10. public abstract void setColor(Color c): is used to set the graphics
current color to the specified color.
11. public abstract void setFont(Font font): is used to set the graphics
current font to the specified font.
Example of Graphics in applet
import java.applet.Applet;
import java.awt.*;
public class GraphicsDemo extends Applet{
public void paint(Graphics g){
g.setColor(Color.red);
g.drawString("Welcome",50, 50);
g.drawLine(20,30,20,300);
g.drawRect(70,100,30,30);
g.fillRect(170,100,30,30);
g.drawOval(70,200,30,30);
g.setColor(Color.pink);
g.fillOval(170,200,30,30);
g.drawArc(90,150,30,30,30,270);
g.fillArc(270,150,30,30,0,180);
}
}
Coding assignment
• Animation in Applet
• Painting in Applet
• Digital Clock in Applet
• Analog Clock in Applet

More Related Content

What's hot

Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
backdoor
 

What's hot (20)

AWT information
AWT informationAWT information
AWT information
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
 
Applets in java
Applets in javaApplets in java
Applets in java
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
 
AWT
AWT AWT
AWT
 
28 awt
28 awt28 awt
28 awt
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Basic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in JavaBasic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in Java
 
Java swing
Java swingJava swing
Java swing
 
GUI Programming with Java
GUI Programming with JavaGUI Programming with Java
GUI Programming with Java
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
25 awt
25 awt25 awt
25 awt
 
Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
 
Awt components
Awt componentsAwt components
Awt components
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
JAVA APPLET BASICS
JAVA APPLET BASICSJAVA APPLET BASICS
JAVA APPLET BASICS
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
 
Layout manager
Layout managerLayout manager
Layout manager
 
Swing
SwingSwing
Swing
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
 

Similar to Java chapter 7

Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06
nrayan
 
Applet Life Cycle in Java with brief introduction
Applet Life Cycle in Java with brief introductionApplet Life Cycle in Java with brief introduction
Applet Life Cycle in Java with brief introduction
devicse
 

Similar to Java chapter 7 (20)

Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
 
L18 applets
L18 appletsL18 applets
L18 applets
 
Applets
AppletsApplets
Applets
 
Applet
AppletApplet
Applet
 
GUI.pdf
GUI.pdfGUI.pdf
GUI.pdf
 
Java Applets
Java AppletsJava Applets
Java Applets
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
 
java Applet Introduction
java Applet Introductionjava Applet Introduction
java Applet Introduction
 
Oops
OopsOops
Oops
 
Applet
AppletApplet
Applet
 
APPLET.pptx
APPLET.pptxAPPLET.pptx
APPLET.pptx
 
Java applet - java
Java applet - javaJava applet - java
Java applet - java
 
Java applet
Java appletJava applet
Java applet
 
Java applet
Java appletJava applet
Java applet
 
Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06
 
Applet Life Cycle in Java with brief introduction
Applet Life Cycle in Java with brief introductionApplet Life Cycle in Java with brief introduction
Applet Life Cycle in Java with brief introduction
 
JAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdfJAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdf
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
 

More from Abdii Rashid (9)

Java chapter 6
Java chapter 6Java chapter 6
Java chapter 6
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Java chapter 4
Java chapter 4Java chapter 4
Java chapter 4
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
Java chapter 2
Java chapter 2Java chapter 2
Java chapter 2
 
object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
 
Chapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for printChapter 8 advanced sorting and hashing for print
Chapter 8 advanced sorting and hashing for print
 
Chapter 7 graphs
Chapter 7 graphsChapter 7 graphs
Chapter 7 graphs
 
Chapter 1 introduction haramaya
Chapter 1 introduction haramayaChapter 1 introduction haramaya
Chapter 1 introduction haramaya
 

Recently uploaded

Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
hublikarsn
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
meharikiros2
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 

Recently uploaded (20)

Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Introduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptxIntroduction to Robotics in Mechanical Engineering.pptx
Introduction to Robotics in Mechanical Engineering.pptx
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata Model
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth Reinforcement
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 

Java chapter 7

  • 2. Java Applets • Overview of Java Applets • Java Applets Vs Java Application
  • 3. Java Applet • Applet is a special type of program that is embedded in the webpage to generate the dynamic content. It runs inside the browser and works at client side.
  • 4. Advantage of Applet • There are many advantages of applet. They are as follows: – It works at client side so less response time. – Secured – It can be executed by browsers running under many platforms, including Linux, Windows, Mac OS etc. Drawback of Applet – Plug-in is required at client browser to execute applet.
  • 5. Hierarchy of Applet As displayed in this diagram, Applet class extends Panel. Panel class extends Container which is the subclass of Component.
  • 6. Lifecycle of Java Applet 1. Applet is initialized. 2. Applet is started. 3. Applet is painted. 4. Applet is stopped. 5. Applet is destroyed.
  • 7. Lifecycle methods for Applet • The java.applet.Applet class 4 life cycle methods and java.awt.Component class provides 1 life cycle methods for an applet. java.applet.Applet class • For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle methods of applet. 1. public void init(): is used to initialized the Applet. It is invoked only once. 2. public void start(): is invoked after the init() method or browser is maximized. It is used to start the Applet. 3. public void stop(): is used to stop the Applet. It is invoked when Applet is stop or browser is minimized. 4. public void destroy(): is used to destroy the Applet. It is invoked only once.
  • 8. Cont… java.awt.Component class • The Component class provides 1 life cycle method of applet. 1. public void paint(Graphics g): is used to paint the Applet. It provides Graphics class object that can be used for drawing oval, rectangle, arc etc. • Who is responsible to manage the life cycle of an applet? Ans. Java Plug-in software
  • 9. How to run an Applet? • There are two ways to run an applet 1. By html file. 2. By appletViewer tool (for testing purpose).
  • 10. Example import java.applet.Applet; import java.awt.Graphics; public class First extends Applet{ public void paint(Graphics g){ g.drawString("welcome",150,150); } }
  • 11. Displaying Graphics in Applet Commonly used methods of Graphics class: 1. public abstract void drawString(String str, int x, int y): is used to draw the specified string. 2. public void drawRect(int x, int y, int width, int height): draws a rectangle with the specified width and height. 3. public abstract void fillRect(int x, int y, int width, int height): is used to fill rectangle with the default color and specified width and height. 4. public abstract void drawOval(int x, int y, int width, int height): is used to draw oval with the specified width and height. 5. public abstract void fillOval(int x, int y, int width, int height): is used to fill oval with the default color and specified width and height.
  • 12. Cont… 6. public abstract void drawLine(int x1, int y1, int x2, int y2): is used to draw line between the points(x1, y1) and (x2, y2). 7. public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): is used draw the specified image. 8. public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used draw a circular or elliptical arc. 9. public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used to fill a circular or elliptical arc. 10. public abstract void setColor(Color c): is used to set the graphics current color to the specified color. 11. public abstract void setFont(Font font): is used to set the graphics current font to the specified font.
  • 13. Example of Graphics in applet import java.applet.Applet; import java.awt.*; public class GraphicsDemo extends Applet{ public void paint(Graphics g){ g.setColor(Color.red); g.drawString("Welcome",50, 50); g.drawLine(20,30,20,300); g.drawRect(70,100,30,30); g.fillRect(170,100,30,30); g.drawOval(70,200,30,30); g.setColor(Color.pink); g.fillOval(170,200,30,30); g.drawArc(90,150,30,30,30,270); g.fillArc(270,150,30,30,0,180); } }
  • 14. Coding assignment • Animation in Applet • Painting in Applet • Digital Clock in Applet • Analog Clock in Applet