SlideShare a Scribd company logo
Applet
Programming
Chapter-5
Marks-20
Introduction
• There are two kinds of Java programs-
–Applications (stand-alone programs)
–Applets.
• An Applet is a small Internet-based program that
has the Graphical User Interface (GUI), written in
the Java programming language.
Introduction
• A Java applet is a small application written in
Java and delivered to users in the form
of bytecode.
• A applet is typically embedded in a Web page
and can be run from a browser.
• Applets can be transported over the Internet
from one computer to another.
How applet differ from application
• Applets are the small programs, applications are
larger programs.
• Applets don't have the main method while in an
application execution starts with the main
method.
• Applications run independently while Applets
cannot. They run from inside the web page.
• Applets cannot read from or write to the files in
the local computer.
Introduction
• An applet can perform
–arithmetic operation,
–display graphics,
–play sounds,
–accept user input,
–create animation and
–play interactive games.
Local and Remote Applets
• We can embed applets into web pages in
two ways-
1. Create our own applets ( Local )
2. Download an applet from remote computer
system (Remote Applet )
Local Applet
• An applet developed locally and stored in local
system is known as local applet.
• When a web page trying to find a local applet, it
does not need to use the Internet.
• It simply searches the directories in the local
system and locates and loads the specified
applet. local applet
Remote Applet
• A remote applet is that which is developed by
someone else and stored on the remote
computer connected to internet.
• Users can download the remote applet onto
there system and run it.
Local Computer Remote Computer
Internet
Steps involved in developing applets
1. Building an applet code (. java file )
2. Creating an executable applet ( .class file )
3. Designing a Web Page using HTML tags.
4. Preparing <APPLET> tag.
5. Incorporating <APPLET> tag into the Web
Page.
6. Creating HTML file.
7. Testing the Applet Code.
Building Applet Code
• It is essential that applet code uses services of
two classes
–Applet class and
–Graphics class.
Chain of classes inherited by Applet class
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
The Applet Class
• The java.applet package is the smallest package
in Java API.
• The Applet class is the only class in the package.
• The Applet class provides life and behaviour to
applet through its methods.
• The Applet class has many methods that are used
to display images, play audio files etc but it has
no main() method.
Methods of Applet Class
• init() :
– used for whatever initializations are needed for
applet.
– Applets can have a default constructor, but it is better
to perform all initializations in the init method
instead of the default constructor.
• start() :
– This method is automatically called after Java calls
the init method.
• stop() :
– This method is automatically called when the user
moves off the page where the applet sits.
• destroy():
– Java calls this method when the browser shuts
down.
paint() Method of Applet Class
• Paint method actually displays the result of applet
code on the screen.
• The output may be text, graphics, or sound.
• Syntax-
public void paint(Graphics g)
• The paint method requires graphics object as an
argument.
• Hence we require to import Graphics class from
java.awt package.
Applet Life Cycle
Born
Running Idle
Dead End
Stopped
Destroyed
Exit browser
Begin
(Load applet) Initialization
Display
paint()
start()
stop()
start()
destroy()
Applet state transition diagram
Born or Initialization State
• An applet begins its life when the web browser
loads its classes and calls its init() method.
• This is called exactly once in Applets lifecycle.
• init() method provides initialization code such as
initialization of variables, loading images or
fonts.
Eg.
public void init()
{
//initialization
Running State
• Once the initialization is complete, the web
browser will call the start() method in the applet.
• This method must called atleast once in the
Applets lifecycle.
• The start() method can also be called if the
Applet is in “Idle” state.
Eg. public void start()
{
//Code
}
Stopped State
• The web browser will call the Applets stop()
method, if the user moved to another web page
while the applet was executing.
• The stop() method is called atleast once in
Applets Lifecycle.
Eg. public void stop()
{
//Code
}
Dead State
• Finally, if the user decides to quit the web
browser, the web browser will free up system
resources by killing the applet before it closes.
• To do so, it will call the applets destroy()
method.
Eg.
public void destroy()
{
// Code
}
Display State
• Applet moves to the display state whenever it
has to perform the output operations on the
screen.
• This happens immediately after the applet
enters into the running state.
• The paint() method is called to accomplish this
task.
Eg.
public void paint(Graphics g)
{
//Display Statements
General format of Applet Code
import java.awt.*;
import java.applet.*;
……………………
public class applet_class_name extends Applet
{ ……………
public void paint(Graphics g)
{
………….//applet operation code
}
}
Example.
import java.awt.*;
import java.applet.*;
public class SimpleApplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("My First Applet",40,40);
}
}
Designing a Web Page
• To execute an applet in a web browser, write a
short HTML text file that contains the
appropriate APPLET tag.
• For above example it is
<html>
<body>
<applet code="SimpleApplet.class" width=200
height=100>
</applet>
</body>
</html>
The Applet tag
<applet
[codebase=codebaseURL]
code=”Applet file”
[ALT=”alternative text]
[name=AppletInstanceName]
Width=pixels
height= pixels
[align= alignment]
>
[<param name=”Attributename” value =”Attribute value”]
[<param name=”Attributename” value =”Attribute value”]
</applet>
Passing Parameter to Applet
• We can supply user-defined parameters to an
applet using <param.....> tag.
• Each <param....> tag has a name ,and a value
attribute.
• For e.g. the color of the text can be changed to
red by an applet using a <param...> tag as
follows
<applet ……>
<param name=“color” value=“RED”>
Passing Parameters to Applet
• To handle parameters, we need to do two things.
1) Include <param.....> tags in HTML document.
2) Provide code in the applet to pass these parameters.
• We can define the init() method in the applet to
get parameters defined in the <param> tags.
•
• This is done using the getParameter() method,
which takes one string argument representing
the name of the parameter and returns a string
containing the value of that parameter.
Example :Parameter Passing
import java.awt.*;
import java.applet.*;
public class HelloJava 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=“HelloJava.class”
width=400
height=400 >
<param name= “String” value= “Applet!” >
</applet>
</body>
</html>
Displaying numerical values
import java.awt.*;
import java.applet.*;
public class Hellojava extends Applet{
public void paint(Graphics g)
{ int value1 =10;
int value2 = 20;
int sum =value1+value2;
String s= "Sum:"+String.valueOf(sum);
g.drawString(s,10,100);
}
Using Control Structure
import java.awt.*;
import java.applet.*;
public class Hellojava extends Applet {
public void paint(Graphics g) {
int y=50;
for(int i=1;i<=10;i++)
{ g.drawString(i+” ”,50,y);
y=y+10;
} } }
/*<applet code=“Hellojava.class” width=300 height=100>
</applet> */

More Related Content

Similar to applet.pptx

Java applet
Java appletJava applet
Java applet
GaneshKumarKanthiah
 
Applets
AppletsApplets
Applets
Nuha Noor
 
Java applet basics
Java applet basicsJava applet basics
Java applet basicsSunil Pandey
 
Java Applets
Java AppletsJava Applets
Java applet
Java appletJava applet
Java applet
Elizabeth alexander
 
Java
JavaJava
JAVA APPLET BASICS
JAVA APPLET BASICSJAVA APPLET BASICS
JAVA APPLET BASICS
Shanid Malayil
 
Appletjava
AppletjavaAppletjava
Appletjava
DEEPIKA T
 
Applet programming1
Applet programming1Applet programming1
Applet programming1
Shah Ishtiyaq Mehfooze
 
Applet
AppletApplet
Applet
pawan2579
 
Applet intro
Applet introApplet intro
Applet intro
Nitin Birari
 
Advanced Programming, Java Programming, Applets.ppt
Advanced Programming, Java Programming, Applets.pptAdvanced Programming, Java Programming, Applets.ppt
Advanced Programming, Java Programming, Applets.ppt
miki304759
 
Java applet
Java appletJava applet
Java applet
Rohan Gajre
 
6applets And Graphics
6applets And Graphics6applets And Graphics
6applets And GraphicsAdil Jafri
 
Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06nrayan
 
Smart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdfSmart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdf
GayathriRHICETCSESTA
 
Smart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdfSmart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdf
GayathriRHICETCSESTA
 
Java applet - java
Java applet - javaJava applet - java
Java applet - java
Rubaya Mim
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
Kavitha713564
 

Similar to applet.pptx (20)

Java applet
Java appletJava applet
Java applet
 
Applets
AppletsApplets
Applets
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Java applet
Java appletJava applet
Java applet
 
Java
JavaJava
Java
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
JAVA APPLET BASICS
JAVA APPLET BASICSJAVA APPLET BASICS
JAVA APPLET BASICS
 
Appletjava
AppletjavaAppletjava
Appletjava
 
Applet programming1
Applet programming1Applet programming1
Applet programming1
 
Applet
AppletApplet
Applet
 
Applet intro
Applet introApplet intro
Applet intro
 
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
Java appletJava applet
Java applet
 
6applets And Graphics
6applets And Graphics6applets And Graphics
6applets And Graphics
 
Applets 101-fa06
Applets 101-fa06Applets 101-fa06
Applets 101-fa06
 
Smart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdfSmart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdf
 
Smart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdfSmart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdf
 
Java applet - java
Java applet - javaJava applet - java
Java applet - java
 
Applet in java new
Applet in java newApplet in java new
Applet in java new
 

More from SachinBhosale73

Dentrifries.pptx
Dentrifries.pptxDentrifries.pptx
Dentrifries.pptx
SachinBhosale73
 
dental product.pptx
dental product.pptxdental product.pptx
dental product.pptx
SachinBhosale73
 
Biochemistry Practicals.pptx
Biochemistry Practicals.pptxBiochemistry Practicals.pptx
Biochemistry Practicals.pptx
SachinBhosale73
 
Acid-bases-buffers.pptx
Acid-bases-buffers.pptxAcid-bases-buffers.pptx
Acid-bases-buffers.pptx
SachinBhosale73
 
abc.pptx
abc.pptxabc.pptx
abc.pptx
SachinBhosale73
 
Manisha.pptx
Manisha.pptxManisha.pptx
Manisha.pptx
SachinBhosale73
 
Research Proposal.pptx
Research Proposal.pptxResearch Proposal.pptx
Research Proposal.pptx
SachinBhosale73
 
Introduction of Deep Learning.pptx
Introduction  of Deep Learning.pptxIntroduction  of Deep Learning.pptx
Introduction of Deep Learning.pptx
SachinBhosale73
 
Unit I- Fundamental of Deep Learning.pptx
Unit I- Fundamental of Deep Learning.pptxUnit I- Fundamental of Deep Learning.pptx
Unit I- Fundamental of Deep Learning.pptx
SachinBhosale73
 
HPLC Final.ppt
HPLC Final.pptHPLC Final.ppt
HPLC Final.ppt
SachinBhosale73
 
bonding_regents_chem.ppt
bonding_regents_chem.pptbonding_regents_chem.ppt
bonding_regents_chem.ppt
SachinBhosale73
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
SachinBhosale73
 
Role of Pharmacist in COVID19.pptx
Role of Pharmacist in COVID19.pptxRole of Pharmacist in COVID19.pptx
Role of Pharmacist in COVID19.pptx
SachinBhosale73
 

More from SachinBhosale73 (15)

Dentrifries.pptx
Dentrifries.pptxDentrifries.pptx
Dentrifries.pptx
 
dental product.pptx
dental product.pptxdental product.pptx
dental product.pptx
 
Biochemistry Practicals.pptx
Biochemistry Practicals.pptxBiochemistry Practicals.pptx
Biochemistry Practicals.pptx
 
Acid-bases-buffers.pptx
Acid-bases-buffers.pptxAcid-bases-buffers.pptx
Acid-bases-buffers.pptx
 
abc.pptx
abc.pptxabc.pptx
abc.pptx
 
Manisha.pptx
Manisha.pptxManisha.pptx
Manisha.pptx
 
Research Proposal.pptx
Research Proposal.pptxResearch Proposal.pptx
Research Proposal.pptx
 
Introduction of Deep Learning.pptx
Introduction  of Deep Learning.pptxIntroduction  of Deep Learning.pptx
Introduction of Deep Learning.pptx
 
Unit I- Fundamental of Deep Learning.pptx
Unit I- Fundamental of Deep Learning.pptxUnit I- Fundamental of Deep Learning.pptx
Unit I- Fundamental of Deep Learning.pptx
 
HPLC Final.ppt
HPLC Final.pptHPLC Final.ppt
HPLC Final.ppt
 
bonding_regents_chem.ppt
bonding_regents_chem.pptbonding_regents_chem.ppt
bonding_regents_chem.ppt
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
java01.ppt
java01.pptjava01.ppt
java01.ppt
 
CSS.ppt
CSS.pptCSS.ppt
CSS.ppt
 
Role of Pharmacist in COVID19.pptx
Role of Pharmacist in COVID19.pptxRole of Pharmacist in COVID19.pptx
Role of Pharmacist in COVID19.pptx
 

Recently uploaded

哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
Kamal Acharya
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptxTOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
nikitacareer3
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
AIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdfAIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdf
RicletoEspinosa1
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
dxobcob
 
Self-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptxSelf-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptx
iemerc2024
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 

Recently uploaded (20)

哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Online aptitude test management system project report.pdf
Online aptitude test management system project report.pdfOnline aptitude test management system project report.pdf
Online aptitude test management system project report.pdf
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptxTOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
AIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdfAIR POLLUTION lecture EnE203 updated.pdf
AIR POLLUTION lecture EnE203 updated.pdf
 
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
一比一原版(Otago毕业证)奥塔哥大学毕业证成绩单如何办理
 
Self-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptxSelf-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptx
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 

applet.pptx

  • 2. Introduction • There are two kinds of Java programs- –Applications (stand-alone programs) –Applets. • An Applet is a small Internet-based program that has the Graphical User Interface (GUI), written in the Java programming language.
  • 3. Introduction • A Java applet is a small application written in Java and delivered to users in the form of bytecode. • A applet is typically embedded in a Web page and can be run from a browser. • Applets can be transported over the Internet from one computer to another.
  • 4. How applet differ from application • Applets are the small programs, applications are larger programs. • Applets don't have the main method while in an application execution starts with the main method. • Applications run independently while Applets cannot. They run from inside the web page. • Applets cannot read from or write to the files in the local computer.
  • 5. Introduction • An applet can perform –arithmetic operation, –display graphics, –play sounds, –accept user input, –create animation and –play interactive games.
  • 6. Local and Remote Applets • We can embed applets into web pages in two ways- 1. Create our own applets ( Local ) 2. Download an applet from remote computer system (Remote Applet )
  • 7. Local Applet • An applet developed locally and stored in local system is known as local applet. • When a web page trying to find a local applet, it does not need to use the Internet. • It simply searches the directories in the local system and locates and loads the specified applet. local applet
  • 8. Remote Applet • A remote applet is that which is developed by someone else and stored on the remote computer connected to internet. • Users can download the remote applet onto there system and run it. Local Computer Remote Computer Internet
  • 9. Steps involved in developing applets 1. Building an applet code (. java file ) 2. Creating an executable applet ( .class file ) 3. Designing a Web Page using HTML tags. 4. Preparing <APPLET> tag. 5. Incorporating <APPLET> tag into the Web Page. 6. Creating HTML file. 7. Testing the Applet Code.
  • 10. Building Applet Code • It is essential that applet code uses services of two classes –Applet class and –Graphics class.
  • 11. Chain of classes inherited by Applet class java.lang.Object | +----java.awt.Component | +----java.awt.Container | +----java.awt.Panel | +----java.applet.Applet
  • 12. The Applet Class • The java.applet package is the smallest package in Java API. • The Applet class is the only class in the package. • The Applet class provides life and behaviour to applet through its methods. • The Applet class has many methods that are used to display images, play audio files etc but it has no main() method.
  • 13. Methods of Applet Class • init() : – used for whatever initializations are needed for applet. – Applets can have a default constructor, but it is better to perform all initializations in the init method instead of the default constructor. • start() : – This method is automatically called after Java calls the init method.
  • 14. • stop() : – This method is automatically called when the user moves off the page where the applet sits. • destroy(): – Java calls this method when the browser shuts down.
  • 15. paint() Method of Applet Class • Paint method actually displays the result of applet code on the screen. • The output may be text, graphics, or sound. • Syntax- public void paint(Graphics g) • The paint method requires graphics object as an argument. • Hence we require to import Graphics class from java.awt package.
  • 16. Applet Life Cycle Born Running Idle Dead End Stopped Destroyed Exit browser Begin (Load applet) Initialization Display paint() start() stop() start() destroy() Applet state transition diagram
  • 17. Born or Initialization State • An applet begins its life when the web browser loads its classes and calls its init() method. • This is called exactly once in Applets lifecycle. • init() method provides initialization code such as initialization of variables, loading images or fonts. Eg. public void init() { //initialization
  • 18. Running State • Once the initialization is complete, the web browser will call the start() method in the applet. • This method must called atleast once in the Applets lifecycle. • The start() method can also be called if the Applet is in “Idle” state. Eg. public void start() { //Code }
  • 19. Stopped State • The web browser will call the Applets stop() method, if the user moved to another web page while the applet was executing. • The stop() method is called atleast once in Applets Lifecycle. Eg. public void stop() { //Code }
  • 20. Dead State • Finally, if the user decides to quit the web browser, the web browser will free up system resources by killing the applet before it closes. • To do so, it will call the applets destroy() method. Eg. public void destroy() { // Code }
  • 21. Display State • Applet moves to the display state whenever it has to perform the output operations on the screen. • This happens immediately after the applet enters into the running state. • The paint() method is called to accomplish this task. Eg. public void paint(Graphics g) { //Display Statements
  • 22. General format of Applet Code import java.awt.*; import java.applet.*; …………………… public class applet_class_name extends Applet { …………… public void paint(Graphics g) { ………….//applet operation code } }
  • 23. Example. import java.awt.*; import java.applet.*; public class SimpleApplet extends Applet { public void paint(Graphics g) { g.drawString("My First Applet",40,40); } }
  • 24. Designing a Web Page • To execute an applet in a web browser, write a short HTML text file that contains the appropriate APPLET tag. • For above example it is <html> <body> <applet code="SimpleApplet.class" width=200 height=100> </applet> </body> </html>
  • 25. The Applet tag <applet [codebase=codebaseURL] code=”Applet file” [ALT=”alternative text] [name=AppletInstanceName] Width=pixels height= pixels [align= alignment] > [<param name=”Attributename” value =”Attribute value”] [<param name=”Attributename” value =”Attribute value”] </applet>
  • 26. Passing Parameter to Applet • We can supply user-defined parameters to an applet using <param.....> tag. • Each <param....> tag has a name ,and a value attribute. • For e.g. the color of the text can be changed to red by an applet using a <param...> tag as follows <applet ……> <param name=“color” value=“RED”>
  • 27. Passing Parameters to Applet • To handle parameters, we need to do two things. 1) Include <param.....> tags in HTML document. 2) Provide code in the applet to pass these parameters. • We can define the init() method in the applet to get parameters defined in the <param> tags. • • This is done using the getParameter() method, which takes one string argument representing the name of the parameter and returns a string containing the value of that parameter.
  • 28. Example :Parameter Passing import java.awt.*; import java.applet.*; public class HelloJava 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)
  • 29. <html> <body> <applet code=“HelloJava.class” width=400 height=400 > <param name= “String” value= “Applet!” > </applet> </body> </html>
  • 30. Displaying numerical values import java.awt.*; import java.applet.*; public class Hellojava extends Applet{ public void paint(Graphics g) { int value1 =10; int value2 = 20; int sum =value1+value2; String s= "Sum:"+String.valueOf(sum); g.drawString(s,10,100); }
  • 31. Using Control Structure import java.awt.*; import java.applet.*; public class Hellojava extends Applet { public void paint(Graphics g) { int y=50; for(int i=1;i<=10;i++) { g.drawString(i+” ”,50,y); y=y+10; } } } /*<applet code=“Hellojava.class” width=300 height=100> </applet> */