Applet Program Lab Practice
Applet Program Lab Practice
Applet Program Lab Practice
OUTPUT:
5. Applet program to draw happy face
import java.awt.*;
import java.applet.*;
public class NewClass extends Applet
{
public void paint(Graphics g)
{
g.drawOval(40,40,120,150); //Head
g.drawOval(57,75,30,20); //Left eye
g.drawOval(110,75,30,20); //Right eye
g.fillOval(68,81,10,10); //Pupil (left)
g.fillOval(121,81,10,10); //Pupil (right)
g.drawOval(85,100,30,30); //Nose
g.fillArc(60,125,80,40,180,180); //Mouth
g.drawOval(25,92,15,30); //Left ear
g.drawOval(160,92,15,30); //Right ear
}}
Output of question number 4.
6. Applet program to draw poygon
Polygons are shapes with many sides. A polygons may be defined as a set of connected lines. The end of
first line is the beginning of second line, and so on,
Syntax:
drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
Draws a closed polygon defined by arrays of x and y coordinates.
import java.awt.*;
import java.applet.*;
public class NewClass extends Applet
{
int x1[]= { 20,120,220,20};
int y1[]= { 20,120,20,20};
int n1= 4;
int x2[]= { 120,220,220,120};
int y2[]= { 120,20,220,120};
int n2= 4;
public void paint(Graphics g)
{
g.drawPolygon(x1,y1,n1);
g.fillPolygon(x2,y2,n2);
}}
OUTPUT:
T
import java.awt.*;
import java.applet.*;
public class LineRect extends Applet
{
public void paint(Graphics g)
{
g.drawLine(10,10,50,50);
g.drawRect(10,60,40,30);
g.fillRect(60,10,30,80);
g.drawRoundRect(10,100,80,50,10,10);
g.fillRoundRect(20,110,60,30,5,5);
g.drawLine(100,10,230,140);
g.drawLine(100,140,230,10);
}
}