0% found this document useful (0 votes)
101 views3 pages

Smiley Applet Programs

The document provides code for two programs to draw a smiling face in an applet program. The first program draws the face, eyes, nose and smile using methods like fillOval, drawPolygon, drawArc and drawLine. The second program simplifies the drawing using only drawOval and drawArc methods to outline the face and draw the smile, and fillOval to fill the eyes in black. Both programs are applet programs that can be embedded in an HTML page to display the smiling face graphic.

Uploaded by

Apurva Ankushrao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views3 pages

Smiley Applet Programs

The document provides code for two programs to draw a smiling face in an applet program. The first program draws the face, eyes, nose and smile using methods like fillOval, drawPolygon, drawArc and drawLine. The second program simplifies the drawing using only drawOval and drawArc methods to outline the face and draw the smile, and fillOval to fill the eyes in black. Both programs are applet programs that can be embedded in an HTML page to display the smiling face graphic.

Uploaded by

Apurva Ankushrao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ATHARVA EDUCATIONAL TRUST'S

ATHARVA COLLEGE OF ENGINEERING


(Approved by AICTE, Recognized by the Government of Maharashtra
& Affiliated to University of Mumbai )
Department of Computer Engineering
Academic Year 2021-22

Assignment No.2

Aim: Write a Program to draw a face with eyes and smile on applet program.

Code:
1. First Program
import java.applet.Applet;
import java.awt.*;

public class SmileyExc extends Applet {

public void paint(Graphics g) {

g.setColor(Color.yellow);
g.fillOval(20,20,150,150); // For face
g.setColor(Color.black);
g.fillOval(50,60,15,25); // Left Eye
g.fillOval(120,60,15,25); // Right Eye
int x[] = {95,85,106,95};
int y[] = {85,104,104,85};
g.drawPolygon(x, y, 4); // Nose
g.drawArc(55,95,78,50,0,-180); // Smile
g.drawLine(50,126,60,116); // Smile arc1
g.drawLine(128,115,139,126); // Smile arc2
}
}

/* <applet code="SmileyExc.class" width="200" height="200">


</applet>
*/
ATHARVA EDUCATIONAL TRUST'S
ATHARVA COLLEGE OF ENGINEERING
(Approved by AICTE, Recognized by the Government of Maharashtra
& Affiliated to University of Mumbai )
Department of Computer Engineering
Academic Year 2021-22

2. Second Program

// Java program to Draw a


// Smiley using Java Applet
import java.applet.*;
import java.awt.*;

public class Smiley extends Applet {


public void paint(Graphics g)
{

// Oval for face outline


g.drawOval(80, 70, 150, 150);
ATHARVA EDUCATIONAL TRUST'S
ATHARVA COLLEGE OF ENGINEERING
(Approved by AICTE, Recognized by the Government of Maharashtra
& Affiliated to University of Mumbai )
Department of Computer Engineering
Academic Year 2021-22

// Ovals for eyes


// with black color filled
g.setColor(Color.BLACK);
g.fillOval(120, 120, 15, 15);
g.fillOval(170, 120, 15, 15);

// Arc for the smile


g.drawArc(130, 180, 50, 20, 180, 180);
}
}

/* <applet code="Smiley.class" width="200" height="200">


</applet>
*/

You might also like