SlideShare uma empresa Scribd logo
1 de 33
APPLET
BY LECTURER SURAJ PANDEY CCT
COLLEGE
Java Applet
 Applet is a special type of program that is embedded in
the webpage to generate the dynamic content. It runs
inside the browser and works at client side.
 Advantage of Applet
 There are many advantages of applet. They are as
follows:
1. It works at client side so less response time.
2. Secured
3. It can be executed by browsers running under many
plateforms, including Linux, Windows, Mac Os etc.
 Drawback of Applet
1. Plugin is required at client browser to execute applet.
BY LECTURER SURAJ PANDEY CCT
COLLEGE
There are some important differences between an applet and a
standalone Java application, including the following:
1. An applet is a Java class that extends the
java.applet.Applet class.
2. Applets are designed to be embedded within an HTML
page.
3. When a user views an HTML page that contains an
applet, the code for the applet is downloaded to the
user's machine.
4. A JVM is required to view an applet. The JVM can be
either a plug-in of the Web browser or a separate
runtime environment.
BY LECTURER SURAJ PANDEY CCT
COLLEGE
5. Applets do not use the main() method for initiating the
execution of the code. Applets, when loaded, automatically
call certain methods of applet class to start and execute the
applet code.
6. Unlike stand alone applications, applets cannot be run
independently. They are run from inside a web page using a
special feature known as HTML tag.
7. Applets cannot communicate with other servers on the
network.
BY LECTURER SURAJ PANDEY CCT
COLLEGE
Preparing to write applets
 We must make sure that java is installed properly and
also ensure that either java aplletviewer or a java-enabled
browser is available. The steps involved in developing and
testing on applet are:
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
BY LECTURER SURAJ PANDEY CCT
COLLEGE
Creating a applet program
 import java.applet.*;
import java.awt.*;
public class HelloWorldApplet extends Applet
{
public void paint (Graphics g)
{
g.drawString ("Hello World", 25, 50);
}
}
BY LECTURER SURAJ PANDEY CCT
COLLEGE
Creating a HTML base Applet
 <html>
<title>The Hello, World Applet</title>
<hr>
<applet code="HelloWorldApplet.class" width="320"
height="120">
</applet>
<hr>
</html>
BY LECTURER SURAJ PANDEY CCT
COLLEGE
Hierarchy of Applet
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 As displayed in the above diagram, Applet class extends
Panel. Panel class extends Container which is the subclass
of Component.
BY LECTURER SURAJ PANDEY CCT
COLLEGE
Applet life cycle
 Every java applet inherit a set of default behaviors from
the Applet class. As a result, when an applet is loaded, it
undergoes a series of changes in its state as shown in fig.
The applet states include:
1. Born on initialization state
2. Running state
3. Idle state
4. Dead or destroyed state
BY LECTURER SURAJ PANDEY CCT
COLLEGE
BY LECTURER SURAJ PANDEY CCT
COLLEGE
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 Initialization state:
 Applet enters the initialization state when it is first
loaded. This is achieved by calling the init() method of
Applet class. The applet is born. At this stage, we may do
the following if required.
 Create objects needed by the applet
 Set up initial values
 Load images or fonts
 Set up colors
The initialization occurs only once in the applet’s life cycle. To
provide any of the behaviors mentioned above, we must
override the init() method:
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 public void init()
{
………….
…………. (Action)
}
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 Running state:
 Applets enter the running state when the system calls the
start() method of applet class. This occurs automatically
after the applet is initialized. Starting can also occur if the
applet is already is ‘stopped’ (idle) state. For example, we
may leave the web page containing the applet temporarily
to another page and return back to the page. This again
starts the applet running.
 public void start()
{
…………….
…………….(Action)
}
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 Idle or stopped state:
 An applet becomes idle when it is stopped from running,
stopping occurs automatically when we leave the page
containing the currently running applet. We can also do so by
calling the stop() method explicitly. If we use a thread to run
the applet, then we must use stop() method to terminate the
thread. We can achieve this by overriding the stop() method:
 public void stop()
{
……………
…………. (Action)
…………..
}
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 Dead state:
 An applet is said to be dead when it is removed from memory.
This occurs automatically by invoking the destroy() method
when we quit the browser. Like initialization, destroying stage
occurs only once in the applet’s life cycle. If the applet has
created any resources, like threads, we may override the
destroy() method to clean up these resources.
 public void display()
{
…………..
…………..(Action)
……………..
}
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 Display state:
 Applet moves to the display state whenever it has to
perform some operations on the screen. This happens
immediately after the applet enters into the running state.
The paint() method is called to accomplish this task.
Almost every applet will have a paint() method.
 public void paint(Graphics g)
{
…………
…………(Display statements)
…………
}
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 After knowing the methods, let us know when they are called
by the browser.
 init() method is called at the time of starting the execution.
This is called only once in the life cycle.
 start() method is called by the init() method. This method is
called a number of times in the life cycle; whenever the applet
is deiconifed , to make the applet active.
 paint() method is called by the start() method. This is called
number of times in the execution.
 stop() method is called whenever the applet window
is iconified to inactivate the applet. This method is called
number of times in the execution.
 destroy() method is called when the applet is closed. This
method is called only once in the life cycle.
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 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.
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 How to run an Applet?
 There are two ways to run an applet
1. By html file.
2. By appletViewer tool (for testing purpose).
BY LECTURER SURAJ PANDEY CCT
COLLEGE
Simple example of Applet by html file:
 To execute the applet by html file, create an applet and
compile it. After that create an html file and place the
applet code in html file. Now click the html file.
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 //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);  
 }  
   
 }  
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 myapplet.html
 <html>  
 <body>  
 <applet code="First.class" width="300" height="300">  
 </applet>  
 </body>  
 </html>  
BY LECTURER SURAJ PANDEY CCT
COLLEGE
Displaying Graphics in Applet
 java.awt.Graphics class provides many methods for graphics programming.
 Commonly used methods of Graphics class:
 public abstract void drawString(String str, int x, int y): is used to
draw the specified string.
 public void drawRect(int x, int y, int width, int height): draws a
rectangle with the specified width and height.
 public abstract void fillRect(int x, int y, int width, int height): is
used to fill rectangle with the default color and specified width and height.
 public abstract void drawOval(int x, int y, int width, int height): is
used to draw oval with the specified width and height.
 public abstract void fillOval(int x, int y, int width, int height): is
used to fill oval with the default color and specified width and height.
 public abstract void drawLine(int x1, int y1, int x2, int y2): is used
to draw line between the points(x1, y1) and (x2, y2).
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 public abstract void drawArc(int x, int y, int
width, int height, int startAngle, int arcAngle): is
used draw a circular or elliptical arc.
 public abstract void fillArc(int x, int y, int width,
int height, int startAngle, int arcAngle): is used to
fill a circular or elliptical arc.
 public abstract void setColor(Color c): is used to
set the graphics current color to the specified color.
 public abstract void setFont(Font font): is used to
set the graphics current font to the specified font.
BY LECTURER SURAJ PANDEY CCT
COLLEGE
Example of Graphics in applet:
 import java.applet.Applet;  
 import java.awt.*;  
 public class GraphicsDemo extends Applet{    
 public void paint(Graphics g){  
 g.setColor(Color.red);  
 g.drawString("Welcome",50, 50);  
 g.drawLine(20,30,20,300);  
 g.drawRect(70,100,30,30);  
 g.fillRect(170,100,30,30);  
 g.drawOval(70,200,30,30);    
 g.setColor(Color.pink);  
 g.fillOval(170,200,30,30);  
 g.drawArc(90,150,30,30,30,270);  
 g.fillArc(270,150,30,30,0,180);    
 }  
 }  
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 myapplet.html
 <html>  
 <body>  
 <applet code="GraphicsDemo.class" width="300" height
="300">  
 </applet>  
 </body>  
 </html>  
BY LECTURER SURAJ PANDEY CCT
COLLEGE
EventHandling in Applet
 As we perform event handling in AWT or Swing, we can
perform it in applet also. Let's see the simple example of
event handling in applet that prints a message by click on
the button.
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 import java.applet.*;  
 import java.awt.*;  
 import java.awt.event.*;  
 public class EventApplet extends Applet implements ActionListener{  
 Button b;  
 TextField tf;  
 public void init(){  
 tf=new TextField();  
 tf.setBounds(30,40,150,20);   
 b=new Button("Click");  
 b.setBounds(80,150,60,50);    
 add(b);add(tf);  
 b.addActionListener(this);   
 setLayout(null);  
 }   
  public void actionPerformed(ActionEvent e){  
   tf.setText("Welcome");  
  }   
 }  
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 In the above example, we have created all the controls in
init() method because it is invoked only once.
BY LECTURER SURAJ PANDEY CCT
COLLEGE
 myapplet.html
 <html>  
 <body>  
 <applet code="EventApplet.class" width="300" height="3
00">  
 </applet>  
 </body>  
 </html>  
BY LECTURER SURAJ PANDEY CCT
COLLEGE
BY LECTURER SURAJ PANDEY CCT
COLLEGE

Mais conteúdo relacionado

Mais procurados (20)

Java applet - java
Java applet - javaJava applet - java
Java applet - java
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Lecture 22
Lecture 22Lecture 22
Lecture 22
 
Oop suplemnertary september 2019
Oop suplemnertary september  2019Oop suplemnertary september  2019
Oop suplemnertary september 2019
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
 
Applet programming
Applet programming Applet programming
Applet programming
 
Java applets
Java appletsJava applets
Java applets
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
 
Java applets
Java appletsJava applets
Java applets
 
27 applet programming
27  applet programming27  applet programming
27 applet programming
 
Applet
 Applet Applet
Applet
 
Applet (1)
Applet (1)Applet (1)
Applet (1)
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
 
ITFT- Applet in java
ITFT- Applet in javaITFT- Applet in java
ITFT- Applet in java
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Applet skelton58
Applet skelton58Applet skelton58
Applet skelton58
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Java applets
Java appletsJava applets
Java applets
 

Semelhante a Basic of Applet

Semelhante a Basic of Applet (20)

Applet in java new
Applet in java newApplet in java new
Applet in java new
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
 
oops with java modules iii & iv.pptx
oops with java modules iii & iv.pptxoops with java modules iii & iv.pptx
oops with java modules iii & iv.pptx
 
Appletjava
AppletjavaAppletjava
Appletjava
 
Oops
OopsOops
Oops
 
171-33B - Java Programming-Building Applets.ppt
171-33B - Java Programming-Building Applets.ppt171-33B - Java Programming-Building Applets.ppt
171-33B - Java Programming-Building Applets.ppt
 
Smart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdfSmart material - Unit 3 (2).pdf
Smart material - Unit 3 (2).pdf
 
Smart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdfSmart material - Unit 3 (1).pdf
Smart material - Unit 3 (1).pdf
 
Java applet
Java appletJava applet
Java applet
 
Applets in Java
Applets in JavaApplets in Java
Applets in Java
 
Applet
AppletApplet
Applet
 
APPLET.pptx
APPLET.pptxAPPLET.pptx
APPLET.pptx
 
Java applet programming concepts
Java  applet programming conceptsJava  applet programming concepts
Java applet programming concepts
 
Java chapter 7
Java chapter 7Java chapter 7
Java chapter 7
 
Java applet
Java appletJava applet
Java applet
 
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
 
L18 applets
L18 appletsL18 applets
L18 applets
 
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 Applets
Java AppletsJava Applets
Java Applets
 

Mais de suraj pandey

Systemcare in computer
Systemcare in computer Systemcare in computer
Systemcare in computer suraj pandey
 
vb.net Constructor and destructor
vb.net Constructor and destructorvb.net Constructor and destructor
vb.net Constructor and destructorsuraj pandey
 
Overloading and overriding in vb.net
Overloading and overriding in vb.netOverloading and overriding in vb.net
Overloading and overriding in vb.netsuraj pandey
 
Basic in Computernetwork
Basic in ComputernetworkBasic in Computernetwork
Basic in Computernetworksuraj pandey
 
History of computer
History of computerHistory of computer
History of computersuraj pandey
 
Basic of Internet&email
Basic of Internet&emailBasic of Internet&email
Basic of Internet&emailsuraj pandey
 
Basic fundamental Computer input/output Accessories
Basic fundamental Computer input/output AccessoriesBasic fundamental Computer input/output Accessories
Basic fundamental Computer input/output Accessoriessuraj pandey
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.netsuraj pandey
 
Transmission mediums in computer networks
Transmission mediums in computer networksTransmission mediums in computer networks
Transmission mediums in computer networkssuraj pandey
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.netsuraj pandey
 
Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computersuraj pandey
 
Computer Fundamental Network topologies
Computer Fundamental Network topologiesComputer Fundamental Network topologies
Computer Fundamental Network topologiessuraj pandey
 
Basic of Computer software
Basic of Computer softwareBasic of Computer software
Basic of Computer softwaresuraj pandey
 
Basic using of Swing in Java
Basic using of Swing in JavaBasic using of Swing in Java
Basic using of Swing in Javasuraj pandey
 
Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Javasuraj pandey
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)suraj pandey
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVAsuraj pandey
 

Mais de suraj pandey (20)

Systemcare in computer
Systemcare in computer Systemcare in computer
Systemcare in computer
 
vb.net Constructor and destructor
vb.net Constructor and destructorvb.net Constructor and destructor
vb.net Constructor and destructor
 
Overloading and overriding in vb.net
Overloading and overriding in vb.netOverloading and overriding in vb.net
Overloading and overriding in vb.net
 
Basic in Computernetwork
Basic in ComputernetworkBasic in Computernetwork
Basic in Computernetwork
 
Computer hardware
Computer hardwareComputer hardware
Computer hardware
 
Dos commands new
Dos commands new Dos commands new
Dos commands new
 
History of computer
History of computerHistory of computer
History of computer
 
Dos commands
Dos commandsDos commands
Dos commands
 
Basic of Internet&email
Basic of Internet&emailBasic of Internet&email
Basic of Internet&email
 
Basic fundamental Computer input/output Accessories
Basic fundamental Computer input/output AccessoriesBasic fundamental Computer input/output Accessories
Basic fundamental Computer input/output Accessories
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.net
 
Transmission mediums in computer networks
Transmission mediums in computer networksTransmission mediums in computer networks
Transmission mediums in computer networks
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
 
Introduction to computer
Introduction to computerIntroduction to computer
Introduction to computer
 
Computer Fundamental Network topologies
Computer Fundamental Network topologiesComputer Fundamental Network topologies
Computer Fundamental Network topologies
 
Basic of Computer software
Basic of Computer softwareBasic of Computer software
Basic of Computer software
 
Basic using of Swing in Java
Basic using of Swing in JavaBasic using of Swing in Java
Basic using of Swing in Java
 
Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Java
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
 

Último

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Último (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Basic of Applet

  • 1. APPLET BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 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.  Advantage of Applet  There are many advantages of applet. They are as follows: 1. It works at client side so less response time. 2. Secured 3. It can be executed by browsers running under many plateforms, including Linux, Windows, Mac Os etc.  Drawback of Applet 1. Plugin is required at client browser to execute applet. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 3. There are some important differences between an applet and a standalone Java application, including the following: 1. An applet is a Java class that extends the java.applet.Applet class. 2. Applets are designed to be embedded within an HTML page. 3. When a user views an HTML page that contains an applet, the code for the applet is downloaded to the user's machine. 4. A JVM is required to view an applet. The JVM can be either a plug-in of the Web browser or a separate runtime environment. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 4. 5. Applets do not use the main() method for initiating the execution of the code. Applets, when loaded, automatically call certain methods of applet class to start and execute the applet code. 6. Unlike stand alone applications, applets cannot be run independently. They are run from inside a web page using a special feature known as HTML tag. 7. Applets cannot communicate with other servers on the network. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 5. Preparing to write applets  We must make sure that java is installed properly and also ensure that either java aplletviewer or a java-enabled browser is available. The steps involved in developing and testing on applet are: 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 BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 6. Creating a applet program  import java.applet.*; import java.awt.*; public class HelloWorldApplet extends Applet { public void paint (Graphics g) { g.drawString ("Hello World", 25, 50); } } BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 7. Creating a HTML base Applet  <html> <title>The Hello, World Applet</title> <hr> <applet code="HelloWorldApplet.class" width="320" height="120"> </applet> <hr> </html> BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 8. Hierarchy of Applet BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 9.  As displayed in the above diagram, Applet class extends Panel. Panel class extends Container which is the subclass of Component. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 10. Applet life cycle  Every java applet inherit a set of default behaviors from the Applet class. As a result, when an applet is loaded, it undergoes a series of changes in its state as shown in fig. The applet states include: 1. Born on initialization state 2. Running state 3. Idle state 4. Dead or destroyed state BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 11. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 12. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 13.  Initialization state:  Applet enters the initialization state when it is first loaded. This is achieved by calling the init() method of Applet class. The applet is born. At this stage, we may do the following if required.  Create objects needed by the applet  Set up initial values  Load images or fonts  Set up colors The initialization occurs only once in the applet’s life cycle. To provide any of the behaviors mentioned above, we must override the init() method: BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 14.  public void init() { …………. …………. (Action) } BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 15.  Running state:  Applets enter the running state when the system calls the start() method of applet class. This occurs automatically after the applet is initialized. Starting can also occur if the applet is already is ‘stopped’ (idle) state. For example, we may leave the web page containing the applet temporarily to another page and return back to the page. This again starts the applet running.  public void start() { ……………. …………….(Action) } BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 16.  Idle or stopped state:  An applet becomes idle when it is stopped from running, stopping occurs automatically when we leave the page containing the currently running applet. We can also do so by calling the stop() method explicitly. If we use a thread to run the applet, then we must use stop() method to terminate the thread. We can achieve this by overriding the stop() method:  public void stop() { …………… …………. (Action) ………….. } BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 17.  Dead state:  An applet is said to be dead when it is removed from memory. This occurs automatically by invoking the destroy() method when we quit the browser. Like initialization, destroying stage occurs only once in the applet’s life cycle. If the applet has created any resources, like threads, we may override the destroy() method to clean up these resources.  public void display() { ………….. …………..(Action) …………….. } BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 18.  Display state:  Applet moves to the display state whenever it has to perform some operations on the screen. This happens immediately after the applet enters into the running state. The paint() method is called to accomplish this task. Almost every applet will have a paint() method.  public void paint(Graphics g) { ………… …………(Display statements) ………… } BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 19.  After knowing the methods, let us know when they are called by the browser.  init() method is called at the time of starting the execution. This is called only once in the life cycle.  start() method is called by the init() method. This method is called a number of times in the life cycle; whenever the applet is deiconifed , to make the applet active.  paint() method is called by the start() method. This is called number of times in the execution.  stop() method is called whenever the applet window is iconified to inactivate the applet. This method is called number of times in the execution.  destroy() method is called when the applet is closed. This method is called only once in the life cycle. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 20.  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. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 21.  How to run an Applet?  There are two ways to run an applet 1. By html file. 2. By appletViewer tool (for testing purpose). BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 22. Simple example of Applet by html file:  To execute the applet by html file, create an applet and compile it. After that create an html file and place the applet code in html file. Now click the html file. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 23.  //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);    }        }   BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 24.  myapplet.html  <html>    <body>    <applet code="First.class" width="300" height="300">    </applet>    </body>    </html>   BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 25. Displaying Graphics in Applet  java.awt.Graphics class provides many methods for graphics programming.  Commonly used methods of Graphics class:  public abstract void drawString(String str, int x, int y): is used to draw the specified string.  public void drawRect(int x, int y, int width, int height): draws a rectangle with the specified width and height.  public abstract void fillRect(int x, int y, int width, int height): is used to fill rectangle with the default color and specified width and height.  public abstract void drawOval(int x, int y, int width, int height): is used to draw oval with the specified width and height.  public abstract void fillOval(int x, int y, int width, int height): is used to fill oval with the default color and specified width and height.  public abstract void drawLine(int x1, int y1, int x2, int y2): is used to draw line between the points(x1, y1) and (x2, y2). BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 26.  public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used draw a circular or elliptical arc.  public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle): is used to fill a circular or elliptical arc.  public abstract void setColor(Color c): is used to set the graphics current color to the specified color.  public abstract void setFont(Font font): is used to set the graphics current font to the specified font. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 27. Example of Graphics in applet:  import java.applet.Applet;    import java.awt.*;    public class GraphicsDemo extends Applet{      public void paint(Graphics g){    g.setColor(Color.red);    g.drawString("Welcome",50, 50);    g.drawLine(20,30,20,300);    g.drawRect(70,100,30,30);    g.fillRect(170,100,30,30);    g.drawOval(70,200,30,30);      g.setColor(Color.pink);    g.fillOval(170,200,30,30);    g.drawArc(90,150,30,30,30,270);    g.fillArc(270,150,30,30,0,180);      }    }   BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 28.  myapplet.html  <html>    <body>    <applet code="GraphicsDemo.class" width="300" height ="300">    </applet>    </body>    </html>   BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 29. EventHandling in Applet  As we perform event handling in AWT or Swing, we can perform it in applet also. Let's see the simple example of event handling in applet that prints a message by click on the button. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 30.  import java.applet.*;    import java.awt.*;    import java.awt.event.*;    public class EventApplet extends Applet implements ActionListener{    Button b;    TextField tf;    public void init(){    tf=new TextField();    tf.setBounds(30,40,150,20);     b=new Button("Click");    b.setBounds(80,150,60,50);      add(b);add(tf);    b.addActionListener(this);     setLayout(null);    }      public void actionPerformed(ActionEvent e){      tf.setText("Welcome");     }     }   BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 31.  In the above example, we have created all the controls in init() method because it is invoked only once. BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 32.  myapplet.html  <html>    <body>    <applet code="EventApplet.class" width="300" height="3 00">    </applet>    </body>    </html>   BY LECTURER SURAJ PANDEY CCT COLLEGE
  • 33. BY LECTURER SURAJ PANDEY CCT COLLEGE