Applet JAVA Update2
Applet JAVA Update2
TOPICS TO BE COVERED…
1 .1 Concept of Applet Programming
⚫ Local and Remote applets
⚫ Difference between applet and application
⚫ Preparing to write applets
⚫ Building applet code
⚫ Applet life cycle
⚫ Creating an executable applet
1.2 Designing a web page:
⚫ Applet tag
⚫ Adding applet to HTML file
⚫ Running the applet
⚫ Passing parameter to applet
1.1 CONCEPT OF APPLET PROGRAMMING
Java supports two types of programming :
1) Application program:
application is a program that runs on
your computer under the operating system of that
Computer.
2) Applet program:
An applet is an application designed to be
transmitted over the Internet and executed by a
Java-compatible Web browser.
APPLET
Applet is a small program that are primarily used in
internet computing, they can be transported over the
internet from one computer to another and run using
applet viewer or java compatible web browser.
Java applet is a java class that you embed in an HTML
page and is downloaded and executed by a web
browser.
Applet can’t be executed directly .
Browser
or
Applet viewer
VM
Applet
LOCAL APPLET
An applet developed locally and stored in a local system
is known as local applet.
User can write his own applets and embed them into
web pages.
LOCAL APPLET
Local applet
L c la
Local Computer
REMOTE APPLET
An applet which is developed by someone else and
stored on a remote computer connected to the Internet
is known as remote Applet.
If our system is connected to the Internet, we can
download the remote applet onto our system via
Internet and then run it.
User can thus download an applet from a remote
computer system.
In order to locate and load a remote applet ,we must
know the applet‟s address on web. This address is
known as URL(Uniform Resource Locator).
URL and must be specified in the applet’s HTML
document as the value of the CODEBASE attribute.
REMOTE APPLET
Internet
Applet Application
Applet is dynamic program Application is static
which is run on browser . program which run using
java interpreter.
Applet do not use the main() Application uses main()
method for initiating the method for execution of
execution of the code. the code.
Applets can not be run Application runs
independently. They must independently using javac
be run under an applet compiler.
viewer or a java compatible
web browser.
DIFFERENCE : APPLET AND APPLICATION
Applet Application
Applets can not read or Application can read write
write files on the web user’s files on the web user’s
disk. disk.
Applet can not communicate Application can
with other server on the communicate with other
network. servers on the network.
Applet can not run any Application program can
program from the local run from local computer.
computer.
Applets are restricted from Application program can
using libraries from other use methods of c, c++
languages such as c,c++. libraries.
APPLET CLASS
Java.applet.Applet class is actually a subclass of
java.awt.Panel.
Java. applet is smallest package in Java API.
It consists of a single class (Applet) and three
interfaces: AppletContext ,AppletStub and
Audioclip.
Applet class contains 21 methods that are used to
display images, play audio files ,respond to events
and obtain information about applet’s execution
environment ,referred as applet’s context.
Java.lang.Object
Java.awt.Component
Java.awt.Container
Java.awt.Panel
Java.applet.Applet
Method Description
Image getImage(URL url): Used to retrieve an Image
identified by URL.
Black 0 0 0
Red 255 0 0
Green 0 255 0
blue 0 0 255
import java.awt.*;
import java.applet.*;
public class Hellojava extends Applet
{
public void paint(Graphics g)
{
g.drawString( “Hello java” ,10,100);
}
}
OUTPUT:
Hello Java
APPLET LIFE CYCLE
<!
----------- Comment section
------------
>
<HEAD>
Head section
Title tag
</HEAD>
<BODY>
</HTML>
HEAD SECTION:
<HEAD>
<TITLE> Welcome to Java Applets
</TITLE>
</HEAD>
</APPLET>
</BODY>
APPLET TAG
(0.0)
(20,20)
( 60,60)
METHODS OF GRAPHICS CLASS
Methods Description
clearRect( ) Erases a rectangular area of canvas
copyArea( ) Copies a rectangular area of the
canvas to other area.
drawArc( ) Draws a hollow arc.
drawLine( ) Draws a straight line.
drawOval( ) Draws a hollow oval
drawPolygon( ) Draws a hollow polygon.
rounded corners
getColor( ) Retrieve the current drawing color
getFontMetrics( )Retrieves information about the
current font.
setColor( ) Sets the drawing color.
setFont( ) Sets the font.
Thank you