Submitted By:-
Kapilpreet Kaur
M.Sc. Bioinformatics IV
Roll No. – MBI-09-05
JAVA
Compiled and Interpreted
Platform Independent and Portable
Object Oriented
Robust and Secure
Distributed
Familiar, Simple and Small
Multithreaded and Interactive
High performance
Dynamic and Extensible
JAVA APPLETS
Are small java programs that are primarily used
in internet computing
Are run using Applet Viewer or any web
browser supporting java.
Can perform arithmetic operations, display
graphics, play sounds, create animations, play
interactive games etc.
Are of 2 types:- Local and Remote applets.
Local Remote
Developed locally Developed by someone
else
Stored in a local system Stored on remote
computer
Does not uses internet Uses internet connection
Simply searches the Downloads remote applet
directory of local system
and loads specified applet onto our system via
internet and run it.
Note:-
We must know the URL of the remote applet
and must be specified in the applet’s HTML
document as the value of the CODEBASE
attribute. Eg.
CODEBASE=http:// www.netserve.com/applet
Writing 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 web page
6. Creating HTML file
7. Testing the applet code
Building Applet Code
Applet code essentially uses services of two
classes namely Applet and Graphics.
the Applet class in java.applet package
provides life to applet through its methods
such as init(), start(), paint().
The Graphics class in java.awt package
contains various methods for drawing.
This requires that applet code imports java.awt
package and java.applet package.
Applet Life Cycle
Creating an executable Applet
Executable applet is the .class file of the
applet, which is obtained by compiling the
source code of the applet.
Syntax:-
Javac HelloJava.java
Successful compiling creates the .class file
of the applet in the same directory.
Designing a web page
Running the Applet
After creating the executable appletand the
html file we will have three files in the current
directory.
1. HelloJava.java
2. HelloJava.class
3. HelloJava.html
Appletviewer is used to run applet with
command:-
appletviewer HelloJava.html
Graphics programming
Java has ability to draw graphics like lines, figures of different
shapes , images, and text in different fonts and styles.
Every applet has its own area of screen known as CANVAS.
Java applet draws graphical image using coordinate system.
Java coordinate system has origin (0,0) in the upper left
corner.
Positive x values are to the right and positive y values are to
the bottom in pixels.
The Graphics Class
Java’s Graphics class includes various methods for
drawing many different types of shapes.
To draw a shape on the screen , we may call one
of the methods availiable in Graphics class.
All the drawing methods have arguments
representing end points, corners, or starting
locations of a shape as values in applet’s
coordinate system.
To draw a shape we only need to use appropriate
method with appropriate arguments.
Drawing methods of Graphics class
Method Description
clearRect() Erases a rectangular area of a canvas.
copyArea() Copies a rectangular area of canvas to another area.
drawArc() Draws a hollow arc.
drawLine() Draws a straight line.
drawOval() Draws a hollow oval.
drawPolygan() Draws a hollow polygon.
drawRect() Draws a hollow rectangle.
drawRoundRect() Draws a hollow rectangle with round corners.
drawString() Displays a text string.
fillArc() Draws a filled arc.
fillOval() Draws a filles oval.
fillPolygon() Draws a filled polygon.
fillRect() Draws a filled rectangle.
fillRoundRect() Draws a filled rectangle with rounded corners.
getColor() Retrieves current drawing color.
getFont() Retrieves the currently used font.
setColor Sets the drawing color.
We can draw lines , rectangles, circles,
ellipses, arcs, polygons, line graphs, bar
charts, etc.. That collectively contribute in
building new shapes through graphics
class methods.