SlideShare uma empresa Scribd logo
1 de 17
ppt15
1
Topics for today
 Java Applets
2
What is an Applet?
• In the computing world, Applet is a small application program
that performs one specific task sometimes running within the
context of a larger program as a plugin (extending capabilities
of a larger program)
• They are not full featured application programs
• Small in size and performs only a small set of tasks
• Eg. Accessories (applications in MS Windows), Web Based
Applets like Quick Time Movies, Flash Movies
Features of Applet
• Applets execute only on the "client" platform environment of
a system, as contrasted from "servlet". As such, an applet
provides functionality or performance beyond the default
capabilities of its container (the browser).
• The container (class) restricts applets' capabilities.
• Applets are written in a language different from the scripting
or HTML language which invokes it. The applet is written in a
compiled language, while the scripting language of the
container is an interpreted language, hence the greater
performance or functionality of the applet. Unlike a
"subroutine", a complete web component can be
implemented as an applet.
What is Java Applet?
• An Java applet is a program written in the Java programming
language that can be included in an HTML page, much in the
same way an image is included in a page and can run in Java
Virtual Machine or Sun’s Applet Viewer
• Java applets were introduced in the first version of the Java
language in 1995
• They can also be written in other form of languages
• Java Applets do not have main() method as an entry point but
instead, have several methods to control specific aspects
of applet execution.
Example 1
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorld extends Applet
{
public void init()
{
// empty for now
}
public void paint(Graphics g)
{ g.drawString("Hello World", 20, 20);
}
}
Steps for writing Applets
• Type in Text Editor and save as Helloworld.java
• Compile as javac Helloworld.java
• Create a HTML file and save it as hello.html and put the below text
<html>
<body>
<applet code=HelloWorld width=30 height=200>
</applet>
</body>
</html>
• Open the HTML file
Understanding what happened
import java.applet.Applet; //importing Applet class
import java.awt.Graphics; //importing Graphic class from AWT from file
java.awt.Graphics.html installed during JDK
installation from file path
X:jdk1.1.7docsapijava.awt.Graphics.html
public class HelloWorld extends Applet //Extends Applet class
{
// init method is used to initialise any variables, objects , necessary method
public void init() {
// empty for now
}
public void paint(Graphics g) //Instance of Graphic class
{ created as g calling draw method
g.drawString("Hello World", 20, 20);
}
}
Applet class
- Provides the platform to design the
appearance and manage the behavior of applet
- Provides GUI component called Panel and many
methods
- Provides init, start, stop, destroy, and paint
methods which has no functionality means they
are empty functions
- Extended class overrides on this methods
- Also provides methods that can be inherited
Example 2
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
public class SimpleApplet extends Applet
{
String text = "I'm a simple applet";
public void init()
{
text = "I'm a simple applet";
setBackground(Color.cyan);
}
public void start()
{ System.out.println("starting...");
}
public void stop()
{
System.out.println("stopping...");
}
public void destroy()
{
System.out.println("preparing to unload...");
}
public void paint(Graphics g)
{
System.out.println("Paint");
g.setColor(Color.blue);
g.drawRect(0, 0, getSize().width -1, getSize().height -1);
g.setColor(Color.red); g.drawString(text, 15, 25);
}
}
Behavior or Life Cycle of Applet
An applet is controlled by the software that runs it.
• The init Method: The init method is called when the applet is first created and
loaded by the underlying software. This method performs one-time operations the
applet needs for its operation such as creating the user interface or setting the
font.
• The start Method: The start method is called when the applet is visited such as
when the end user goes to a web page with an applet on it. The example prints a
string to the console to tell you the applet is starting. In a more complex applet,
the start method would do things required at the start of the applet such as begin
animation or play sounds.
After the start method executes, the event thread calls the paint method to draw
to the applet's Panel. A thread is a single sequential flow of control within the
applet, and every applet can run in multiple threads.
• Stop Method: The stop method stops the applet when the applet is no longer on
the screen such as when the end user goes to another web page. Like stop
animation or sounds.
• Destroy Methods: The destroy method is called when the browser exits.
Extending Class
Packages
• Import statement used in Java applet program
calls the class which are stored in different
packages
• eg. java.applet is a Package and Applet is a
ready made precompiled JavaAPI class for
import java.applet.Applet statement
• eg. java.lang.* calls all the packages within
that package
Advantages of using Java Applet
• Provides web applications with interactive features that cannot be
provided by HTML
• Can be executed by most browsers in any platforms due to Java
bytecodes independence
• The same applet can work on "all" installed versions of Java at the
same time, rather than just the latest plug-in version only
• It can move the work from the server to the client, making a web
solution more scalable with the number of users/clients
Technique to refer with HTML
Using <APPLET> tag
Disadvantages of Java Applet
• It requires the Java plug-in and for organizations that only
allow software installed by the administrators by contacting
the administrator to request installation of the Java plug-in.
• Some applets require a specific JRE or newer JRE and if
required than available on the system the user running it the
first time will need to wait for the large JRE download to
complete.
• Java automatic installation or update may fail if a proxy server
is used to access the web. This makes applets with specific
requirements impossible to run unless Java is manually
updated. The Java automatic updater that is part of a Java
installation also may be complex to configure if it must work
through a proxy.
Jsp applet

Mais conteúdo relacionado

Mais procurados

ITFT- Applet in java
ITFT- Applet in javaITFT- Applet in java
ITFT- Applet in javaAtul Sehdev
 
Basics of applets.53
Basics of applets.53Basics of applets.53
Basics of applets.53myrajendra
 
Appl clas nd architect.56
Appl clas nd architect.56Appl clas nd architect.56
Appl clas nd architect.56myrajendra
 
Java Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet ProgramsJava Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet ProgramsTrinity Dwarka
 
Applet programming in java
Applet programming in javaApplet programming in java
Applet programming in javaVidya Bharti
 
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...seleniumconf
 
Java applets
Java appletsJava applets
Java appletslopjuan
 
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...Ryan Baxter
 

Mais procurados (20)

Java applets
Java appletsJava applets
Java applets
 
ITFT- Applet in java
ITFT- Applet in javaITFT- Applet in java
ITFT- Applet in java
 
Applet progming
Applet progmingApplet progming
Applet progming
 
java applets
java appletsjava applets
java applets
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
 
Java applets
Java appletsJava applets
Java applets
 
Basics of applets.53
Basics of applets.53Basics of applets.53
Basics of applets.53
 
Java Applet
Java AppletJava Applet
Java Applet
 
Appl clas nd architect.56
Appl clas nd architect.56Appl clas nd architect.56
Appl clas nd architect.56
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet ProgramsJava Programming- Introduction to Java Applet Programs
Java Programming- Introduction to Java Applet Programs
 
Applets
AppletsApplets
Applets
 
Applet programming in java
Applet programming in javaApplet programming in java
Applet programming in java
 
Java applet
Java appletJava applet
Java applet
 
Applet
AppletApplet
Applet
 
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
 
Java applets
Java appletsJava applets
Java applets
 
Applet (1)
Applet (1)Applet (1)
Applet (1)
 
Java applet-basics
Java applet-basicsJava applet-basics
Java applet-basics
 
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
 

Semelhante a Jsp applet

Semelhante a Jsp applet (20)

applet.pptx
applet.pptxapplet.pptx
applet.pptx
 
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
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
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)
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Advanced Programming, Java Programming, Applets.ppt
Advanced Programming, Java Programming, Applets.pptAdvanced Programming, Java Programming, Applets.ppt
Advanced Programming, Java Programming, Applets.ppt
 
JAVA APPLET BASICS
JAVA APPLET BASICSJAVA APPLET BASICS
JAVA APPLET BASICS
 
Applet.pptx
Applet.pptxApplet.pptx
Applet.pptx
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
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
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
 
Applet in java
Applet in javaApplet in java
Applet in java
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Java applet
Java appletJava applet
Java applet
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
APPLET.pptx
APPLET.pptxAPPLET.pptx
APPLET.pptx
 
Applet
AppletApplet
Applet
 
Java applet
Java appletJava applet
Java applet
 

Mais de Sanoj Kumar

Internet of things
Internet of thingsInternet of things
Internet of thingsSanoj Kumar
 
Big data and Internet
Big data and InternetBig data and Internet
Big data and InternetSanoj Kumar
 
A New Security Model For Distributed System
A New Security Model For Distributed SystemA New Security Model For Distributed System
A New Security Model For Distributed SystemSanoj Kumar
 
A New Form of Dos attack in Cloud
A New Form of Dos attack in CloudA New Form of Dos attack in Cloud
A New Form of Dos attack in CloudSanoj Kumar
 
Inverted page tables basic
Inverted page tables basicInverted page tables basic
Inverted page tables basicSanoj Kumar
 
Hardware virtualization basic
Hardware virtualization basicHardware virtualization basic
Hardware virtualization basicSanoj Kumar
 
Dos attack basic
Dos attack basicDos attack basic
Dos attack basicSanoj Kumar
 
Steganography basic
Steganography basicSteganography basic
Steganography basicSanoj Kumar
 
Digital signatures
Digital signaturesDigital signatures
Digital signaturesSanoj Kumar
 

Mais de Sanoj Kumar (14)

Internet of things
Internet of thingsInternet of things
Internet of things
 
Corba
CorbaCorba
Corba
 
Dns
DnsDns
Dns
 
Big data and Internet
Big data and InternetBig data and Internet
Big data and Internet
 
Ajax
AjaxAjax
Ajax
 
A New Security Model For Distributed System
A New Security Model For Distributed SystemA New Security Model For Distributed System
A New Security Model For Distributed System
 
A New Form of Dos attack in Cloud
A New Form of Dos attack in CloudA New Form of Dos attack in Cloud
A New Form of Dos attack in Cloud
 
Biometrics
BiometricsBiometrics
Biometrics
 
IPC SOCKET
IPC SOCKETIPC SOCKET
IPC SOCKET
 
Inverted page tables basic
Inverted page tables basicInverted page tables basic
Inverted page tables basic
 
Hardware virtualization basic
Hardware virtualization basicHardware virtualization basic
Hardware virtualization basic
 
Dos attack basic
Dos attack basicDos attack basic
Dos attack basic
 
Steganography basic
Steganography basicSteganography basic
Steganography basic
 
Digital signatures
Digital signaturesDigital signatures
Digital signatures
 

Último

MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 

Último (20)

MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 

Jsp applet

  • 2. Topics for today  Java Applets 2
  • 3. What is an Applet? • In the computing world, Applet is a small application program that performs one specific task sometimes running within the context of a larger program as a plugin (extending capabilities of a larger program) • They are not full featured application programs • Small in size and performs only a small set of tasks • Eg. Accessories (applications in MS Windows), Web Based Applets like Quick Time Movies, Flash Movies
  • 4. Features of Applet • Applets execute only on the "client" platform environment of a system, as contrasted from "servlet". As such, an applet provides functionality or performance beyond the default capabilities of its container (the browser). • The container (class) restricts applets' capabilities. • Applets are written in a language different from the scripting or HTML language which invokes it. The applet is written in a compiled language, while the scripting language of the container is an interpreted language, hence the greater performance or functionality of the applet. Unlike a "subroutine", a complete web component can be implemented as an applet.
  • 5. What is Java Applet? • An Java applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page and can run in Java Virtual Machine or Sun’s Applet Viewer • Java applets were introduced in the first version of the Java language in 1995 • They can also be written in other form of languages • Java Applets do not have main() method as an entry point but instead, have several methods to control specific aspects of applet execution.
  • 6. Example 1 import java.applet.Applet; import java.awt.Graphics; public class HelloWorld extends Applet { public void init() { // empty for now } public void paint(Graphics g) { g.drawString("Hello World", 20, 20); } }
  • 7. Steps for writing Applets • Type in Text Editor and save as Helloworld.java • Compile as javac Helloworld.java • Create a HTML file and save it as hello.html and put the below text <html> <body> <applet code=HelloWorld width=30 height=200> </applet> </body> </html> • Open the HTML file
  • 8. Understanding what happened import java.applet.Applet; //importing Applet class import java.awt.Graphics; //importing Graphic class from AWT from file java.awt.Graphics.html installed during JDK installation from file path X:jdk1.1.7docsapijava.awt.Graphics.html public class HelloWorld extends Applet //Extends Applet class { // init method is used to initialise any variables, objects , necessary method public void init() { // empty for now } public void paint(Graphics g) //Instance of Graphic class { created as g calling draw method g.drawString("Hello World", 20, 20); } }
  • 9. Applet class - Provides the platform to design the appearance and manage the behavior of applet - Provides GUI component called Panel and many methods - Provides init, start, stop, destroy, and paint methods which has no functionality means they are empty functions - Extended class overrides on this methods - Also provides methods that can be inherited
  • 10. Example 2 import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; public class SimpleApplet extends Applet { String text = "I'm a simple applet"; public void init() { text = "I'm a simple applet"; setBackground(Color.cyan); } public void start() { System.out.println("starting..."); } public void stop() { System.out.println("stopping..."); }
  • 11. public void destroy() { System.out.println("preparing to unload..."); } public void paint(Graphics g) { System.out.println("Paint"); g.setColor(Color.blue); g.drawRect(0, 0, getSize().width -1, getSize().height -1); g.setColor(Color.red); g.drawString(text, 15, 25); } }
  • 12. Behavior or Life Cycle of Applet An applet is controlled by the software that runs it. • The init Method: The init method is called when the applet is first created and loaded by the underlying software. This method performs one-time operations the applet needs for its operation such as creating the user interface or setting the font. • The start Method: The start method is called when the applet is visited such as when the end user goes to a web page with an applet on it. The example prints a string to the console to tell you the applet is starting. In a more complex applet, the start method would do things required at the start of the applet such as begin animation or play sounds. After the start method executes, the event thread calls the paint method to draw to the applet's Panel. A thread is a single sequential flow of control within the applet, and every applet can run in multiple threads. • Stop Method: The stop method stops the applet when the applet is no longer on the screen such as when the end user goes to another web page. Like stop animation or sounds. • Destroy Methods: The destroy method is called when the browser exits.
  • 14. Packages • Import statement used in Java applet program calls the class which are stored in different packages • eg. java.applet is a Package and Applet is a ready made precompiled JavaAPI class for import java.applet.Applet statement • eg. java.lang.* calls all the packages within that package
  • 15. Advantages of using Java Applet • Provides web applications with interactive features that cannot be provided by HTML • Can be executed by most browsers in any platforms due to Java bytecodes independence • The same applet can work on "all" installed versions of Java at the same time, rather than just the latest plug-in version only • It can move the work from the server to the client, making a web solution more scalable with the number of users/clients Technique to refer with HTML Using <APPLET> tag
  • 16. Disadvantages of Java Applet • It requires the Java plug-in and for organizations that only allow software installed by the administrators by contacting the administrator to request installation of the Java plug-in. • Some applets require a specific JRE or newer JRE and if required than available on the system the user running it the first time will need to wait for the large JRE download to complete. • Java automatic installation or update may fail if a proxy server is used to access the web. This makes applets with specific requirements impossible to run unless Java is manually updated. The Java automatic updater that is part of a Java installation also may be complex to configure if it must work through a proxy.