0% found this document useful (0 votes)
2 views

JavaApplets

Java applets are programs that run in a browser's context, downloaded from a web server and invoked via the APPLET tag in web pages. They have a defined life cycle with methods such as init(), start(), stop(), and destroy(), and are subject to security restrictions that prevent file access and limit network connections. The java.awt.Graphics class provides methods for graphics programming within applets, allowing for the drawing and filling of shapes and text.

Uploaded by

nirmaclg
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

JavaApplets

Java applets are programs that run in a browser's context, downloaded from a web server and invoked via the APPLET tag in web pages. They have a defined life cycle with methods such as init(), start(), stop(), and destroy(), and are subject to security restrictions that prevent file access and limit network connections. The java.awt.Graphics class provides methods for graphics programming within applets, allowing for the drawing and filling of shapes and text.

Uploaded by

nirmaclg
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

02/26/25 1

Java applets

02/26/25 2
Introduction
Java applets are one of three kinds of Java
programs:
 An application is a standalone program that can be
invoked from the command line.
 An applet is a program that runs in the context of a
browser session.
 A servlet is a program that is invoked on a server
program, and it runs in the context of a web server
process.

02/26/25 3
Applets, web page, client, server
 Applets are programs stored on a web server,
similar to web pages.
 When an applet is referred to in a web page
that has been fetched and processed by a
browser, the browser generates a request to
fetch (or download) the applet program, then
executes the applet program in the browser’s
execution context on the client host.

02/26/25 4
Applet Execution - 2
 Life Cycle of an Applet:
 init: This method is intended for whatever initialization
is needed for an applet.
 start: This method is automatically called after init
method. It is also called whenever user returns to the
page containing the applet after visiting other pages.
 stop: This method is automatically called whenever the
user moves away from the page containing applets.
This method can be used to stop an animation.
 destroy: This method is only called when the browser
shuts down normally.


Ref: http://java.sun.com/docs/books/tutorial/deployment/applet/index.html /

02/26/25 5
Applet Execution - 3
 The applet is running and rendered on
the web page.
 Every Applet needs to implement one of
more of the init(), the start( ) and the
paint( ) methods.
 At the end of the execution, the stop( )
method is invoked, followed by the
destroy( ) method to deallocate the
applet’s resources.

02/26/25 6
Applet Security

For security reasons, applets that are loaded over


the network have several restrictions.
 an applet cannot ordinarily read or write files

on the computer that it's executing on.


 an applet cannot make network connections

except to the host that it came from.


Ref: http://java.sun.com/docs/books/tutorial/deployment/applet/index.html/

02/26/25 7
Summary
 An applet is a Java class
 Its code is downloaded from a web server
 It runs in the browser’s environment on the client host
 It is invoked by a browser when it scans a web page and
encounters a class specified with the APPLET tag
 For security reason, the execution of an applet is
normally subject to restrictions:
 applets cannot access files in the file system on the client host
 Applets cannot make network connection exception to the
server host from which it originated

02/26/25 8
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.
02/26/25 9
 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).
 public abstract void drawArc(int x, int y, int
width, int height, int startAngle, int
arcAngle): is used draw a circular or elliptical arc.
02/26/25 10
 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.
02/26/25 11

You might also like