Displaying graphics in applet

Displaying graphics in applet

There are many method for graphics.

public void drawRect(int x, int y, int width, int height): It is used to draws a rectangle.
public abstract void fillRect(int x, int y, int width, int height): It is used to fill rectangle with the default color.
public abstract void drawOval(int x, int y, int width, int height): It is used to draw oval.
public abstract void fillOval(int x, int y, int width, int height): It is used to fill oval.
public abstract void drawLine(int x1, int y1, int x2, int y2): It is used to draw line between the points(x1, y1) and (x2, y2).
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): It is used draw the specified image.
public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): It is used draw a circular arc.
public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle): It is used to fill a circular arc.

Example

test.java

import java.applet.Applet;
import java.awt.*;
public class test extends Applet
{
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawString(“Welcome”,50, 50);
g.drawRect(70,100,30,30);
g.fillRect(170,100,30,30);
g.drawOval(70,200,30,30);
g.fillOval(170,200,30,30);
g.drawArc(90,150,30,30,30,270);
g.fillArc(270,150,30,30,0,180);
}
}

New.html

<html>
<body>
<applet code=”test.class” width=”300″ height=”300″>
</applet>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *