Event Handling
Applet - Basics; Applet architecture; Applet UNIT 4: Applets & life cycle; Applet
display methods; Repaint; Status window; Passing parameters to applets;
Getdocumentbase(); Getcodebase(); Applet context and showdocument().
Event Handling – Event handling mechanisms; Delegation event model; Event
classes; Sources of events; Event listener interfaces; Handling mouse and
keyboard events; Adapter classes; Inner classes.
Unit 4
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.
Advantages of Applet
It works at client side so less response time.
Secured
It can be executed by browsers running under
many plateforms, including Linux, Windows,
Mac Os etc.
• Drawback of Applet
Plugin is required at client browser to execute
applet.
Lifecycle of Java Applet
Applet is initialized.
Applet is started.
Applet is painted.
Applet is stopped.
Applet is destroyed.
init()
start()
stop()
destroy()
paint
do other work
Lifecycle methods for Applet:
 java.applet.Applet class
• For creating any applet java.applet.Applet class must
be inherited. It provides 4 life cycle methods of applet.
 public void init(): is used to initialized the Applet. It is
invoked only once.
 public void start(): is invoked after the init() method or
browser is maximized. It is used to start the Applet.
 public void stop(): is used to stop the Applet. It is
invoked when Applet is stop or browser is minimized.
 public void destroy(): is used to destroy the Applet. It
is invoked only once.
• Each applet has four major events in
its lifetime:
–Initialization --- init()
–Starting --- start()
–Painting --- paint(Graphics)
–Stopping --- stop()
–Destroying --- destroy()
java.awt.Component class
The Component class provides 1 life cycle
method of applet.
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.
How to run an Applet?
• There are two ways to run an applet
By html file.
By appletViewer tool
Example of Applet by html file:
To execute the applet by html file:
1. Create an applet and compile it.
2. Create an html file and place the applet code
in html file.
//First.java
import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet{
public void paint(Graphics g){
g.drawString("welcome",150,150);
}
}
//myapplet.html
<html>
<body>
<applet code="First.class" width="300" height="
300">
</applet>
</body>
</html>
Example of Applet by appletviewer
tool
To execute the applet by appletviewer tool
1.Create an applet that contains applet tag in
comment and compile it.
2. After that run it by: appletviewer First.java
//First.java
import java.applet.Applet;
import java.awt.Graphics;
public class First extends Applet{
public void paint(Graphics g){
g.drawString("welcome to applet",150,150);
}
}
/*
<applet code="First.class" width="300" height="300">
</applet>
*/ c:>javac First.java
c:>appletviewer First.java
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);
}
}
<html>
<body>
<applet code="GraphicsDemo.class"
width="300" height="300">
</applet>
</body>
</html>
Passing Parameters to Applet
• Supply user-defined parameters to an applet
using <PARAM> tags.
<applet>
<param name=text value=“Applet>
</applet>
import java.awt.*;
import java.applet.*;
public class HelloParam extends Applet
{
String str;
public void init()
{
str=getParameter(“string”);
if(str==null)
str=“Java”;
str=“Hello”+str;
}
public void paint(Graphics g)
{
g.drawString(str,10,10);
}
<html>
<body>
<applet code=“HelloParam.class”
width=400 height=200>
<param name=“string”
value=“Applet!”>
</param>
</body>
</html>
• Write a applet program to pass name and age
of a person and print it .
import java.awt.*;
import java.applet.*;
public class MyApplet extends Applet
{
String n;
String a;
public void init()
{
n = getParameter("name");
a = getParameter("age");
}
public void paint(Graphics g)
{
g.drawString("Name is: " + n, 20, 20);
g.drawString("Age is: " + a, 20, 40);
}
}
/*
<applet code="MyApplet" height="300" width="500">
<param name="name" value="Ramesh" />
<param name="age" value="25" />
</applet>
*/
Output

More Related Content

PPT
1 - Introduction to PL/SQL
PDF
Exception handling in plsql
PDF
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
PPTX
Java applets
PPTX
Introduction to JAVA
PPTX
graphics programming in java
PPTX
Array in c#
PPTX
Anchor tag HTML Presentation
1 - Introduction to PL/SQL
Exception handling in plsql
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Java applets
Introduction to JAVA
graphics programming in java
Array in c#
Anchor tag HTML Presentation

What's hot (20)

PPT
Introduction to method overloading &amp; method overriding in java hdm
PPTX
Interface in java
PPT
MYSQL - PHP Database Connectivity
PPTX
Database Connectivity in PHP
PDF
HTTP Request and Response Structure
PPTX
Data types in java
PPTX
Java applet - java
PPT
PHP - Introduction to File Handling with PHP
PPTX
C# Arrays
PPT
Applet life cycle
PDF
Nested Queries Lecture
PPTX
Arrays in java
PPTX
PPTX
Method overloading
PPTX
Final keyword in java
PPT
Joins in SQL
PPT
Software tools
PPTX
PPTX
MULTI THREADING IN JAVA
PPTX
Core java complete ppt(note)
Introduction to method overloading &amp; method overriding in java hdm
Interface in java
MYSQL - PHP Database Connectivity
Database Connectivity in PHP
HTTP Request and Response Structure
Data types in java
Java applet - java
PHP - Introduction to File Handling with PHP
C# Arrays
Applet life cycle
Nested Queries Lecture
Arrays in java
Method overloading
Final keyword in java
Joins in SQL
Software tools
MULTI THREADING IN JAVA
Core java complete ppt(note)
Ad

Similar to Java Applets (20)

PPTX
PPTX
Java Apple dndkorksnsbsjdkkdjejdjrdndjdj
PPT
Applet ppt for higher understanding education
PPTX
Applet (1)
PPT
Basic of Applet
PPT
Applet and graphics programming
PPTX
Appletjava
PPTX
Introduction To Applets methods and simple examples
PDF
27 applet programming
PPSX
Java Applet
PPTX
Applets in java
PPTX
Java Applet presentation............pptx
PDF
Advanced programming chapter 2 - Java Applet.pdf
PPTX
Applets in Java
PPT
Slide8appletv2 091028110313-phpapp01
PPTX
"Interactive Web Applications Using Java".pptx
PPTX
Applet in java new
PPTX
PPTX
oops with java modules iii & iv.pptx
PPT
java programming - applets
Java Apple dndkorksnsbsjdkkdjejdjrdndjdj
Applet ppt for higher understanding education
Applet (1)
Basic of Applet
Applet and graphics programming
Appletjava
Introduction To Applets methods and simple examples
27 applet programming
Java Applet
Applets in java
Java Applet presentation............pptx
Advanced programming chapter 2 - Java Applet.pdf
Applets in Java
Slide8appletv2 091028110313-phpapp01
"Interactive Web Applications Using Java".pptx
Applet in java new
oops with java modules iii & iv.pptx
java programming - applets
Ad

More from Dr. Jasmine Beulah Gnanadurai (20)

PPTX
Chapter 4 Requirements Engineering2.pptx
PPTX
Chapter 4 Requirement Engineering1 .pptx
PPTX
Chapter 2 Software Processes Processes.pptx
PPT
Programming in Python Lists and its methods .ppt
PPT
Introduction to UML, class diagrams, sequence diagrams
PPT
Software Process Models in Software Engineering
PPT
ch03-Data Modeling Using the Entity-Relationship (ER) Model.ppt
PPT
Process Model in Software Engineering Concepts
PPTX
Arrays and Detailed explanation of Array
PPTX
Data Warehouse_Architecture.pptx
PPTX
DMQL(Data Mining Query Language).pptx
PPTX
PPTX
KBS Architecture.pptx
PPTX
Knowledge Representation in AI.pptx
PPTX
File allocation methods (1)
PPTX
Segmentation in operating systems
PPTX
Association rules apriori algorithm
Chapter 4 Requirements Engineering2.pptx
Chapter 4 Requirement Engineering1 .pptx
Chapter 2 Software Processes Processes.pptx
Programming in Python Lists and its methods .ppt
Introduction to UML, class diagrams, sequence diagrams
Software Process Models in Software Engineering
ch03-Data Modeling Using the Entity-Relationship (ER) Model.ppt
Process Model in Software Engineering Concepts
Arrays and Detailed explanation of Array
Data Warehouse_Architecture.pptx
DMQL(Data Mining Query Language).pptx
KBS Architecture.pptx
Knowledge Representation in AI.pptx
File allocation methods (1)
Segmentation in operating systems
Association rules apriori algorithm

Recently uploaded (20)

PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PPTX
TNA_Presentation-1-Final(SAVE)) (1).pptx
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
HVAC Specification 2024 according to central public works department
PDF
International_Financial_Reporting_Standa.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PDF
advance database management system book.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
Hazard Identification & Risk Assessment .pdf
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Computer Architecture Input Output Memory.pptx
Environmental Education MCQ BD2EE - Share Source.pdf
TNA_Presentation-1-Final(SAVE)) (1).pptx
B.Sc. DS Unit 2 Software Engineering.pptx
HVAC Specification 2024 according to central public works department
International_Financial_Reporting_Standa.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Uderstanding digital marketing and marketing stratergie for engaging the digi...
Share_Module_2_Power_conflict_and_negotiation.pptx
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
FORM 1 BIOLOGY MIND MAPS and their schemes
advance database management system book.pdf
What if we spent less time fighting change, and more time building what’s rig...
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
History, Philosophy and sociology of education (1).pptx
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Hazard Identification & Risk Assessment .pdf
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Computer Architecture Input Output Memory.pptx

Java Applets

  • 1. Event Handling Applet - Basics; Applet architecture; Applet UNIT 4: Applets & life cycle; Applet display methods; Repaint; Status window; Passing parameters to applets; Getdocumentbase(); Getcodebase(); Applet context and showdocument(). Event Handling – Event handling mechanisms; Delegation event model; Event classes; Sources of events; Event listener interfaces; Handling mouse and keyboard events; Adapter classes; Inner classes. Unit 4
  • 2. 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.
  • 3. Advantages of Applet It works at client side so less response time. Secured It can be executed by browsers running under many plateforms, including Linux, Windows, Mac Os etc. • Drawback of Applet Plugin is required at client browser to execute applet.
  • 4. Lifecycle of Java Applet Applet is initialized. Applet is started. Applet is painted. Applet is stopped. Applet is destroyed.
  • 6. Lifecycle methods for Applet:  java.applet.Applet class • For creating any applet java.applet.Applet class must be inherited. It provides 4 life cycle methods of applet.  public void init(): is used to initialized the Applet. It is invoked only once.  public void start(): is invoked after the init() method or browser is maximized. It is used to start the Applet.  public void stop(): is used to stop the Applet. It is invoked when Applet is stop or browser is minimized.  public void destroy(): is used to destroy the Applet. It is invoked only once.
  • 7. • Each applet has four major events in its lifetime: –Initialization --- init() –Starting --- start() –Painting --- paint(Graphics) –Stopping --- stop() –Destroying --- destroy()
  • 8. java.awt.Component class The Component class provides 1 life cycle method of applet. 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.
  • 9. How to run an Applet? • There are two ways to run an applet By html file. By appletViewer tool
  • 10. Example of Applet by html file: To execute the applet by html file: 1. Create an applet and compile it. 2. Create an html file and place the applet code in html file.
  • 11. //First.java import java.applet.Applet; import java.awt.Graphics; public class First extends Applet{ public void paint(Graphics g){ g.drawString("welcome",150,150); } }
  • 13. Example of Applet by appletviewer tool To execute the applet by appletviewer tool 1.Create an applet that contains applet tag in comment and compile it. 2. After that run it by: appletviewer First.java
  • 14. //First.java import java.applet.Applet; import java.awt.Graphics; public class First extends Applet{ public void paint(Graphics g){ g.drawString("welcome to applet",150,150); } } /* <applet code="First.class" width="300" height="300"> </applet> */ c:>javac First.java c:>appletviewer First.java
  • 15. 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); } } <html> <body> <applet code="GraphicsDemo.class" width="300" height="300"> </applet> </body> </html>
  • 16. Passing Parameters to Applet • Supply user-defined parameters to an applet using <PARAM> tags. <applet> <param name=text value=“Applet> </applet>
  • 17. import java.awt.*; import java.applet.*; public class HelloParam extends Applet { String str; public void init() { str=getParameter(“string”); if(str==null) str=“Java”; str=“Hello”+str; } public void paint(Graphics g) { g.drawString(str,10,10); } <html> <body> <applet code=“HelloParam.class” width=400 height=200> <param name=“string” value=“Applet!”> </param> </body> </html>
  • 18. • Write a applet program to pass name and age of a person and print it .
  • 19. import java.awt.*; import java.applet.*; public class MyApplet extends Applet { String n; String a; public void init() { n = getParameter("name"); a = getParameter("age"); } public void paint(Graphics g) { g.drawString("Name is: " + n, 20, 20); g.drawString("Age is: " + a, 20, 40); } } /* <applet code="MyApplet" height="300" width="500"> <param name="name" value="Ramesh" /> <param name="age" value="25" /> </applet> */