SlideShare a Scribd company logo
Applet and Graphics
Programming
Applet Programming
• Applets are small Java programs that are primarily used
in Internet computing.
• They can be transported over the Internet from one
computer to another and run using the Applet Viewer or
any Web browser that supports Java.
• An applet, like any application program, can do many
things for us. It can perform arithmetic operations,
display graphics, play sounds, accept user input, create
animation, and play interactive games.
Local and Remote Applets
• An applet developed locally and stored in a local system
is known as a local applet.
• A remote applet is that which is developed by someone
else and stored on a remote computer connected to the
Internet.
• In order to locate and load a remote applet, we must
know the applet’s address on the Web. This address is
known as Uniform Resource Locator(URL).
How Applets differ from
Applications
• Applets do not use the main() methods for initiating the
execution of the code.
• 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.
• Applets cannot read from or write to the files in the local
computer.
• Applets cannot communicate with other servers on the
network.
• Applets cannot run any program the local computer.
• Applets are restricted form using libraries form other
languages such as C or C++.
To Write Applets
• Building an applet code (.java file)
• Creating an executable applet (*.class file)
• Designing a Web page using HTML tags
• Preparing <APPLET> tag
• Incorporating <APPLET> tag into the Web page
• Creating HTML file
• Testing the applet code
Chain of classes inherited by Applet
Class
java..lang.Object
java.applet.Applet
java.awt.Panel
java.awt.Container
java.awt.Component
Applet Life Cycle
• The applet states include:
– Born or initialization state
– Running state
– Idle state
– Dead or destroyed state
Born
Running Idle
Dead
Begin
(Load Applet)
Initalization
Start( )
stop( )
start( )
Stopped
destroy ( )
EndDestroyed
Exit of Broswer
paint ( )
Display
An applet’s state transition diagram
Applet Life Cycle
• 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.
– The initialization occurs only once in the applets’life cycle.
– To provide any of the behaviours mentioned above, we must
override the init ( ) method:
public void init( )
{
//statements
}
• Running State
– Applet enters the running state when the system calls the start
( ) method of Applet Class.
– The occurs automatically after the applet is initialized.
– Starting can also occur if the applet is already in “stopped”
(Idle ) state.
– Unlike init( ) method, the start ( ) method may be called more
than once.
public void start()
{
// statements
}
Applet Life Cycle
• 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.
public void stop( )
{
//statements
}
Applet Life Cycle
• 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.
public void destroy( )
{
//statements
}
Applet Life Cycle
• Display state
– Applet moves to the display state whenever it has to perform some
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.
– Almost every applet will have a paint( ) method.
– Paint( ) method is inherited form the Component class , a super class
of Applet.
public void paint (Graphics g)
{
//statements
}
Applet Life Cycle
import java.awt.*;
import java.applet.*;
public class HelloJava extends Applet
{
public void paint(Graphics g)
{
g.drawString("Hello Java",10,100);
}
}
<html>
<body>
<applet code = "HelloJava.class"
height=“100” width =“200”>
</applet>
</body></html>
Applet Tag
• The <Applet. .>tag supplies the name of the applet to be
loaded and tells the browser how much space the applet
requires.
• <APPLET> tag specifies three things:
– Same of the applet
– Width of the applet (in pixels)
– Height of the applet (in pixels)
Passing Parameters to Applets
• We can supply user-defined parameters to an applet using
<PARAM…> tags.
• Each <PARAM…>tag has a name attribute such as color and a value
attribute such as red.
• Inside the applet code, the applet can refer to that parameter by name
to find its value.
• To set up and handle parameters, we need to do two things:
– Include appropriate <PARAM…> tags in the HTML document
– Provide Code in the applet to parse these parameters.
• Parameters are passed to an applet when it is loaded. We can define
the init() method in the applet to get hold of the 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 the parameter.
import java.awt.*;
import java.applet.*;
public class JavaParam extends Applet
{
String s;
public void init()
{
s =
getParameter("uname");
if(s==null)
s = “ABC”;
s = "Hello" + s;
}
public void paint(Graphics g)
{
g.drawString(s,10,100);
}
}
<html>
<body>
<APPLE CODE =
JavaParam.class
width=400 height = 200>
<PARAM NAME = "uname"
VALUE="ruchita">
</APPLE>
</body>
</html>

More Related Content

PPTX
Advance Java Topics (J2EE)
PPT
Operator Overloading
PPT
Object Oriented Language
PPTX
Introduction to oop
PDF
Arrays in Java
PPTX
Training on Core java | PPT Presentation | Shravan Sanidhya
PPTX
core java
Advance Java Topics (J2EE)
Operator Overloading
Object Oriented Language
Introduction to oop
Arrays in Java
Training on Core java | PPT Presentation | Shravan Sanidhya
core java

What's hot (20)

PPTX
Java programming course for beginners
PPT
Inheritance in java
PPTX
Introduction to java
PPT
Chapter 13 - Recursion
PPTX
Java Beans
PPT
Oops in Java
PPT
Graphics programming in Java
PDF
Polymorphism In Java
PPTX
Applet and graphics programming
PPTX
graphics programming in java
DOC
Final JAVA Practical of BCA SEM-5.
PPTX
Constructor in java
PPSX
JDBC: java DataBase connectivity
PPTX
Introduction to Spring Boot
PPT
Final keyword in java
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
PPTX
Method overloading
PPT
Applet life cycle
PPT
Array in Java
PPTX
JDBC ppt
Java programming course for beginners
Inheritance in java
Introduction to java
Chapter 13 - Recursion
Java Beans
Oops in Java
Graphics programming in Java
Polymorphism In Java
Applet and graphics programming
graphics programming in java
Final JAVA Practical of BCA SEM-5.
Constructor in java
JDBC: java DataBase connectivity
Introduction to Spring Boot
Final keyword in java
Basic Concepts of OOPs (Object Oriented Programming in Java)
Method overloading
Applet life cycle
Array in Java
JDBC ppt
Ad

Viewers also liked (20)

PDF
27 applet programming
PDF
Java Applet and Graphics
PDF
ITFT- Applet in java
PPT
Java applet
PPT
java graphics
PPTX
Java Graphics Programming
PPT
Javalecture 1
PPT
Client Side Programming with Applet
PPTX
Exception handling in java
PPTX
Satish training ppt
PPT
JavaYDL13
PPT
Basics of applets.53
DOCX
Srgoc java
PPT
L5 classes, objects, nested and inner class
PPTX
Applets in java
PPT
exception handling
PPT
Java Applet
PPTX
L18 applets
PPTX
Static keyword ppt
27 applet programming
Java Applet and Graphics
ITFT- Applet in java
Java applet
java graphics
Java Graphics Programming
Javalecture 1
Client Side Programming with Applet
Exception handling in java
Satish training ppt
JavaYDL13
Basics of applets.53
Srgoc java
L5 classes, objects, nested and inner class
Applets in java
exception handling
Java Applet
L18 applets
Static keyword ppt
Ad

Similar to Applet and graphics programming (20)

PPTX
MSBTE Computer Engineering Java applet.pptx
PPTX
applet.pptx
PPTX
Applet intro
PPTX
Java applet
PPTX
Applets
PPTX
Introduction To Applets methods and simple examples
PPTX
Applets in Java
PPTX
Java applet
PPT
Advanced Programming, Java Programming, Applets.ppt
PPT
Java: Java Applets
PPTX
PROGRAMMING IN JAVA- unit 4-part I
PPT
Unit 7 Java
PPT
Java programming Java programming Java programming
PPT
Java files and io streams
PPTX
PDF
Java applet basics
PPT
java programming - applets
PPTX
Applet.pptx
PPTX
Till applet skeleton
PPT
Slide8appletv2 091028110313-phpapp01
MSBTE Computer Engineering Java applet.pptx
applet.pptx
Applet intro
Java applet
Applets
Introduction To Applets methods and simple examples
Applets in Java
Java applet
Advanced Programming, Java Programming, Applets.ppt
Java: Java Applets
PROGRAMMING IN JAVA- unit 4-part I
Unit 7 Java
Java programming Java programming Java programming
Java files and io streams
Java applet basics
java programming - applets
Applet.pptx
Till applet skeleton
Slide8appletv2 091028110313-phpapp01

Recently uploaded (20)

PDF
Trump Administration's workforce development strategy
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
master seminar digital applications in india
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
01-Introduction-to-Information-Management.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Trump Administration's workforce development strategy
Yogi Goddess Pres Conference Studio Updates
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Cell Structure & Organelles in detailed.
master seminar digital applications in india
GDM (1) (1).pptx small presentation for students
Orientation - ARALprogram of Deped to the Parents.pptx
Computing-Curriculum for Schools in Ghana
Abdominal Access Techniques with Prof. Dr. R K Mishra
01-Introduction-to-Information-Management.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Weekly quiz Compilation Jan -July 25.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Microbial diseases, their pathogenesis and prophylaxis
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Complications of Minimal Access Surgery at WLH
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc

Applet and graphics programming

  • 2. Applet Programming • Applets are small Java programs that are primarily used in Internet computing. • They can be transported over the Internet from one computer to another and run using the Applet Viewer or any Web browser that supports Java. • An applet, like any application program, can do many things for us. It can perform arithmetic operations, display graphics, play sounds, accept user input, create animation, and play interactive games.
  • 3. Local and Remote Applets • An applet developed locally and stored in a local system is known as a local applet. • A remote applet is that which is developed by someone else and stored on a remote computer connected to the Internet. • In order to locate and load a remote applet, we must know the applet’s address on the Web. This address is known as Uniform Resource Locator(URL).
  • 4. How Applets differ from Applications • Applets do not use the main() methods for initiating the execution of the code. • 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. • Applets cannot read from or write to the files in the local computer. • Applets cannot communicate with other servers on the network. • Applets cannot run any program the local computer. • Applets are restricted form using libraries form other languages such as C or C++.
  • 5. To Write Applets • Building an applet code (.java file) • Creating an executable applet (*.class file) • Designing a Web page using HTML tags • Preparing <APPLET> tag • Incorporating <APPLET> tag into the Web page • Creating HTML file • Testing the applet code
  • 6. Chain of classes inherited by Applet Class java..lang.Object java.applet.Applet java.awt.Panel java.awt.Container java.awt.Component
  • 7. Applet Life Cycle • The applet states include: – Born or initialization state – Running state – Idle state – Dead or destroyed state
  • 8. Born Running Idle Dead Begin (Load Applet) Initalization Start( ) stop( ) start( ) Stopped destroy ( ) EndDestroyed Exit of Broswer paint ( ) Display An applet’s state transition diagram
  • 9. Applet Life Cycle • 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. – The initialization occurs only once in the applets’life cycle. – To provide any of the behaviours mentioned above, we must override the init ( ) method: public void init( ) { //statements }
  • 10. • Running State – Applet enters the running state when the system calls the start ( ) method of Applet Class. – The occurs automatically after the applet is initialized. – Starting can also occur if the applet is already in “stopped” (Idle ) state. – Unlike init( ) method, the start ( ) method may be called more than once. public void start() { // statements } Applet Life Cycle
  • 11. • 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. public void stop( ) { //statements } Applet Life Cycle
  • 12. • 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. public void destroy( ) { //statements } Applet Life Cycle
  • 13. • Display state – Applet moves to the display state whenever it has to perform some 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. – Almost every applet will have a paint( ) method. – Paint( ) method is inherited form the Component class , a super class of Applet. public void paint (Graphics g) { //statements } Applet Life Cycle
  • 14. import java.awt.*; import java.applet.*; public class HelloJava extends Applet { public void paint(Graphics g) { g.drawString("Hello Java",10,100); } } <html> <body> <applet code = "HelloJava.class" height=“100” width =“200”> </applet> </body></html>
  • 15. Applet Tag • The <Applet. .>tag supplies the name of the applet to be loaded and tells the browser how much space the applet requires. • <APPLET> tag specifies three things: – Same of the applet – Width of the applet (in pixels) – Height of the applet (in pixels)
  • 16. Passing Parameters to Applets • We can supply user-defined parameters to an applet using <PARAM…> tags. • Each <PARAM…>tag has a name attribute such as color and a value attribute such as red. • Inside the applet code, the applet can refer to that parameter by name to find its value. • To set up and handle parameters, we need to do two things: – Include appropriate <PARAM…> tags in the HTML document – Provide Code in the applet to parse these parameters. • Parameters are passed to an applet when it is loaded. We can define the init() method in the applet to get hold of the 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 the parameter.
  • 17. import java.awt.*; import java.applet.*; public class JavaParam extends Applet { String s; public void init() { s = getParameter("uname"); if(s==null) s = “ABC”; s = "Hello" + s; } public void paint(Graphics g) { g.drawString(s,10,100); } } <html> <body> <APPLE CODE = JavaParam.class width=400 height = 200> <PARAM NAME = "uname" VALUE="ruchita"> </APPLE> </body> </html>