JAVA
APPLETS
• Introduction Applest
▫Java
programs that can be embedded in Hypertext Markup Language (HTML) documents.
▫The
browser that executes an applet is generically known as the applet container
import java.awt.*;
import java.applet.*;
/*
<applet code=applet1 width=200 height=400>
</applet>
*/
public class applet1 extends Applet
{
public void
paint(Graphics g)
{
g.drawString("Hello Welcome to java", 40,100);
}
}
APPLET LIFE CYCLE
•public void init()
This method is used
to initialize
variables of applet. Called only once.
•public void start()
▫ Called
immediately after init and can be called
repeatedly.
▫ Used
to start animation threads
•public void paint(Graphics g)
▫This
method is called automatically after
start() method when applet begins its
execution.
•public void stop()
▫ Called
when the browser leaves the page
▫ Used
to stop animation threads
•public void destroy()
▫Called
automatically by applet when it ends up
its activity. It releases the resources
used by
applet.
/*
<applet code=app width=500 height=500>
</applet>
*/
public class app extends Applet
{
String str;
public void init()
{
str +=" init";
}
public void start()
{
str +="
start";
}
public void stop()
{
str +=" stop";
}
public void
paint(Graphics g)
{
g.drawString(str,10,20);
}
}
GRAPHICS IN APPLETS
Drawing Lines
public void drawLine(int x1,int y1,int x2,int y2);
Drawing Rectangles
public void drawRect(int x,int y , int width , int
height);
public void drawRoundRect(int x,int y , int width , int
height,int arcw ,int arch);
public void draw3DRect(int x, int y , int width , int
height , boolean raised);
public void fillRect(int x,int y , int width , int
height);
public void fillRoundRect(int x,int y , int width , int
height,int arcw ,int arch);
public void fill3DRect(int x, int y , int width , int
height , boolean raised);
public void clearRect(int x, int y, int width , int
height);
{clears the
rectangle and fills it with background color }
Drawing Ovals & Circles
public void drawOval(int x,int y , int width , int height);
public void fillOval(int x,int y , int width , int height);
Drawing Ovals & Circles
public void drawArc(int x ,int y , int width , int height ,int
startangle , int arcangle);
public void fillArc(int x , int y , int width , int height ,int
startangle , int arcangle);
Drawing Polygons
public void drawPolygon(int xpoints[ ] ,int ypoints[ ] , int
nPoints);
public void fillPolygon(int xpoints[ ] ,int ypoints[ ] , int
nPoints);
Public void drawPolygon(Polygon P); {Draw outline}
Drawing PolyLines
To draw open-Ended polylines
public void drawPolyline(int xpoints[ ] ,int ypoints[ ] , int
nPoints);
Colors In Graphics
•Belongs
to java.awt.color;
•
Some common color constants…..
•Color.black
•Color.blue
•Color.cyan
•Color.darkGray
•Color.gray
•Color.green
•Color.lightGray
•Color.magenta
•Color.orange
•Color.pink
•Color.red
•Color.white
•Color.yellow
0 comments:
Post a Comment