SlideShare a Scribd company logo
SSBN Degree College, ATP M Vishnuvardhan
Java Applets
-M Vishnuvardhan,
Dept. of Computer Science,
SSBN Degree College, ATP
SSBN Degree College, ATP M Vishnuvardhan
» Java programs are divided into two main
categories, applets and applications
» An application is an ordinary Java program
» An applet is a kind of Java program that can
be run across the Internet
Applets: Introduction
SSBN Degree College, ATP M Vishnuvardhan
» Applets are mainly used convert a static web
page to dynamic page
» Web is created with the help of Hypertext
markup language (HTML).
» Web site is collection of webpages of a
particular organization.
» A browser is a software which is used to browse
the internet ie., used to view web pages
Applets: Introduction
SSBN Degree College, ATP M Vishnuvardhan
» Applets do not use main() method
» Applets needs html code to run
» Applets are run by Java enabled
web browser.
» Applets are by default GUI Apps.
Applets vs. Applications
SSBN Degree College, ATP M Vishnuvardhan
» To deal with applets in java a special class is
defined in java.applet package called as
Applet.
» Applet class contains five special methods
init() :- used for initialization of applet
start() :- used to start an applet
paint() :- used to paint the contents of the
applet on the window
stop() :- used to stop an applet
destroy() :- used to destroy an applet
»Applet methods are automatically called one
after another once they are loaded into web
browser
Applet Class
SSBN Degree College, ATP M Vishnuvardhan
In order to create an applet the following steps
are to be followed
»Create a class by extending applet class
»Override any one of the applet class method
»Compile the program to obtain the class file
»Create a html document and embed the applet
»Run the applet along with the html page in
java enabled web browser
Creation of Applets
SSBN Degree College, ATP M Vishnuvardhan
// Sample Applet program
import java.awt.*;
import java.applet.*;
public class DemoApp extends Applet
{
public void paint(Graphics g)
{
g.drawString(“Java applets”, 50,50);
}
}
Note:- After compiling the program embed the applet in a
html file and open in java enabled web browser.
Creation of Applets
SSBN Degree College, ATP M Vishnuvardhan
Html is a language used to design a web page
Basic structure of html file is
<html>
<! ------Comment Section ---- >
<head> <title> title of the page </title>
</head>
<body>
Body of the web page
</body>
</html>
HTML
SSBN Degree College, ATP M Vishnuvardhan
Commonly used html tags
<b> … </b>
<i> … </i>
<u> … </u>
<h1> .. </h1> to <h7> … </h7>
<applet> …. </applet>
HTML
SSBN Degree College, ATP M Vishnuvardhan
An Applet is embedded in a html file using
<applet> tag. Applet tag contains three main
attributes
Code :- specifies the class name of applet
Height :- specifies the height of the applet
Width :- specifies the width of the applet
Alignment :- specifies the alignment of applet
Hspace :- specifies the horizontal and
Vspace :- vertical space around the applet
EG:-
<applet code=“Demo” width=“300” height=“300”>
</applet>
Embedding an applet in html file
SSBN Degree College, ATP M Vishnuvardhan
Applet life cycle contains four necessary states
1. Born or Initialization state
2. Running State
3. Idle state
4. Dead state
In this four states applet class five methods are
executed on after another.
Applet Life Cycle
SSBN Degree College, ATP M Vishnuvardhan
Applet Life Cycle
Born
Running Idle
Dead
start()
stop()
destroy()
start()
paint()
Loading of
applet
Exit of
browser
SSBN Degree College, ATP M Vishnuvardhan
It is possible to pass data from a html page to
applet program. This can be done with the
help of <PARAM> tag in html
<APPLET .. . .. . .>
<PARAM name=“ ..” value=”…”/>
</APPLET>
Here the name corresponds the name of the
parameter and value associates the value of
the parameter
Passing parameters to Applet
SSBN Degree College, ATP M Vishnuvardhan
The parameters from the <PARAM> tag can be
read in the applet program with the help of
following method
String getParameter(String name):
returns the value associated with the
specified parameter.
Passing parameters to Applet
SSBN Degree College, ATP M Vishnuvardhan
Questions
Ad

More Related Content

What's hot (20)

Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Veerabadra Badra
 
PROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptxPROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptx
SeethaDinesh
 
Java - Interfaces & Packages
Java - Interfaces & PackagesJava - Interfaces & Packages
Java - Interfaces & Packages
Arindam Ghosh
 
Servlets
ServletsServlets
Servlets
Akshay Ballarpure
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 
1z0 808[1]
1z0 808[1]1z0 808[1]
1z0 808[1]
hildebrando vargas
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
Sessions and cookies
Sessions and cookiesSessions and cookies
Sessions and cookies
www.netgains.org
 
JVM
JVMJVM
JVM
baabtra.com - No. 1 supplier of quality freshers
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
Kongu Engineering College, Perundurai, Erode
 
what is java?
  what is java?  what is java?
what is java?
Binary Informatics
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
Naveen Sihag
 
Elements of Java Language
Elements of Java Language Elements of Java Language
Elements of Java Language
Hitesh-Java
 
Java Basics
Java BasicsJava Basics
Java Basics
shivamgarg_nitj
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Andres Baravalle
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
Enterprise java unit-2_chapter-3
Enterprise  java unit-2_chapter-3Enterprise  java unit-2_chapter-3
Enterprise java unit-2_chapter-3
sandeep54552
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaion
Pritom Chaki
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 

Similar to Java applets (20)

Applets in Java
Applets in JavaApplets in Java
Applets in Java
RamaPrabha24
 
Java applets
Java appletsJava applets
Java applets
Pihu Goel
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
Sunil Pandey
 
MSBTE Computer Engineering Java applet.pptx
MSBTE Computer Engineering Java applet.pptxMSBTE Computer Engineering Java applet.pptx
MSBTE Computer Engineering Java applet.pptx
kunalgaikwad1705
 
Java
JavaJava
Java
janani thirupathi
 
Java applet-basics
Java applet-basicsJava applet-basics
Java applet-basics
kanchanmahajan23
 
Java applet-basics
Java applet-basicsJava applet-basics
Java applet-basics
kanchanmahajan23
 
Java files and io streams
Java files and io streamsJava files and io streams
Java files and io streams
RubaNagarajan
 
applet.pptx
applet.pptxapplet.pptx
applet.pptx
SachinBhosale73
 
PROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part IPROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part I
SivaSankari36
 
Appletjava
AppletjavaAppletjava
Appletjava
DEEPIKA T
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
sanchi Sharma
 
Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)
Daroko blog(www.professionalbloggertricks.com)
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
Nexus
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
Gomathi Gomu
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
amitksaha
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
suraj pandey
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
Javalecture 1
Javalecture 1Javalecture 1
Javalecture 1
mrinalbhutani
 
Java applets
Java appletsJava applets
Java applets
Pihu Goel
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
Sunil Pandey
 
MSBTE Computer Engineering Java applet.pptx
MSBTE Computer Engineering Java applet.pptxMSBTE Computer Engineering Java applet.pptx
MSBTE Computer Engineering Java applet.pptx
kunalgaikwad1705
 
Java files and io streams
Java files and io streamsJava files and io streams
Java files and io streams
RubaNagarajan
 
PROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part IPROGRAMMING IN JAVA- unit 4-part I
PROGRAMMING IN JAVA- unit 4-part I
SivaSankari36
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
Nexus
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
amitksaha
 
Class notes(week 10) on applet programming
Class notes(week 10) on applet programmingClass notes(week 10) on applet programming
Class notes(week 10) on applet programming
Kuntal Bhowmick
 
Ad

More from M Vishnuvardhan Reddy (20)

Python Sets_Dictionary.pptx
Python Sets_Dictionary.pptxPython Sets_Dictionary.pptx
Python Sets_Dictionary.pptx
M Vishnuvardhan Reddy
 
Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
M Vishnuvardhan Reddy
 
Python Control Structures.pptx
Python Control Structures.pptxPython Control Structures.pptx
Python Control Structures.pptx
M Vishnuvardhan Reddy
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
M Vishnuvardhan Reddy
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
M Vishnuvardhan Reddy
 
Python Operators.pptx
Python Operators.pptxPython Operators.pptx
Python Operators.pptx
M Vishnuvardhan Reddy
 
Python Datatypes.pptx
Python Datatypes.pptxPython Datatypes.pptx
Python Datatypes.pptx
M Vishnuvardhan Reddy
 
DataScience.pptx
DataScience.pptxDataScience.pptx
DataScience.pptx
M Vishnuvardhan Reddy
 
Html forms
Html formsHtml forms
Html forms
M Vishnuvardhan Reddy
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
M Vishnuvardhan Reddy
 
Java Threads
Java ThreadsJava Threads
Java Threads
M Vishnuvardhan Reddy
 
Java Streams
Java StreamsJava Streams
Java Streams
M Vishnuvardhan Reddy
 
Scanner class
Scanner classScanner class
Scanner class
M Vishnuvardhan Reddy
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
M Vishnuvardhan Reddy
 
Java intro
Java introJava intro
Java intro
M Vishnuvardhan Reddy
 
Exception handling
Exception handling Exception handling
Exception handling
M Vishnuvardhan Reddy
 
Control structures
Control structuresControl structures
Control structures
M Vishnuvardhan Reddy
 
Constructors
ConstructorsConstructors
Constructors
M Vishnuvardhan Reddy
 
Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
M Vishnuvardhan Reddy
 
Shell sort
Shell sortShell sort
Shell sort
M Vishnuvardhan Reddy
 
Ad

Recently uploaded (20)

Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
May Patch Tuesday
May Patch TuesdayMay Patch Tuesday
May Patch Tuesday
Ivanti
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 

Java applets

  • 1. SSBN Degree College, ATP M Vishnuvardhan Java Applets -M Vishnuvardhan, Dept. of Computer Science, SSBN Degree College, ATP
  • 2. SSBN Degree College, ATP M Vishnuvardhan » Java programs are divided into two main categories, applets and applications » An application is an ordinary Java program » An applet is a kind of Java program that can be run across the Internet Applets: Introduction
  • 3. SSBN Degree College, ATP M Vishnuvardhan » Applets are mainly used convert a static web page to dynamic page » Web is created with the help of Hypertext markup language (HTML). » Web site is collection of webpages of a particular organization. » A browser is a software which is used to browse the internet ie., used to view web pages Applets: Introduction
  • 4. SSBN Degree College, ATP M Vishnuvardhan » Applets do not use main() method » Applets needs html code to run » Applets are run by Java enabled web browser. » Applets are by default GUI Apps. Applets vs. Applications
  • 5. SSBN Degree College, ATP M Vishnuvardhan » To deal with applets in java a special class is defined in java.applet package called as Applet. » Applet class contains five special methods init() :- used for initialization of applet start() :- used to start an applet paint() :- used to paint the contents of the applet on the window stop() :- used to stop an applet destroy() :- used to destroy an applet »Applet methods are automatically called one after another once they are loaded into web browser Applet Class
  • 6. SSBN Degree College, ATP M Vishnuvardhan In order to create an applet the following steps are to be followed »Create a class by extending applet class »Override any one of the applet class method »Compile the program to obtain the class file »Create a html document and embed the applet »Run the applet along with the html page in java enabled web browser Creation of Applets
  • 7. SSBN Degree College, ATP M Vishnuvardhan // Sample Applet program import java.awt.*; import java.applet.*; public class DemoApp extends Applet { public void paint(Graphics g) { g.drawString(“Java applets”, 50,50); } } Note:- After compiling the program embed the applet in a html file and open in java enabled web browser. Creation of Applets
  • 8. SSBN Degree College, ATP M Vishnuvardhan Html is a language used to design a web page Basic structure of html file is <html> <! ------Comment Section ---- > <head> <title> title of the page </title> </head> <body> Body of the web page </body> </html> HTML
  • 9. SSBN Degree College, ATP M Vishnuvardhan Commonly used html tags <b> … </b> <i> … </i> <u> … </u> <h1> .. </h1> to <h7> … </h7> <applet> …. </applet> HTML
  • 10. SSBN Degree College, ATP M Vishnuvardhan An Applet is embedded in a html file using <applet> tag. Applet tag contains three main attributes Code :- specifies the class name of applet Height :- specifies the height of the applet Width :- specifies the width of the applet Alignment :- specifies the alignment of applet Hspace :- specifies the horizontal and Vspace :- vertical space around the applet EG:- <applet code=“Demo” width=“300” height=“300”> </applet> Embedding an applet in html file
  • 11. SSBN Degree College, ATP M Vishnuvardhan Applet life cycle contains four necessary states 1. Born or Initialization state 2. Running State 3. Idle state 4. Dead state In this four states applet class five methods are executed on after another. Applet Life Cycle
  • 12. SSBN Degree College, ATP M Vishnuvardhan Applet Life Cycle Born Running Idle Dead start() stop() destroy() start() paint() Loading of applet Exit of browser
  • 13. SSBN Degree College, ATP M Vishnuvardhan It is possible to pass data from a html page to applet program. This can be done with the help of <PARAM> tag in html <APPLET .. . .. . .> <PARAM name=“ ..” value=”…”/> </APPLET> Here the name corresponds the name of the parameter and value associates the value of the parameter Passing parameters to Applet
  • 14. SSBN Degree College, ATP M Vishnuvardhan The parameters from the <PARAM> tag can be read in the applet program with the help of following method String getParameter(String name): returns the value associated with the specified parameter. Passing parameters to Applet
  • 15. SSBN Degree College, ATP M Vishnuvardhan Questions
  翻译: