This is a Java Program to Display Human Face using Applet
We have to write a program in Java such that it displays a human face using applet.
For displaying human face using applet, we can have the following set of input and output.
When the Applet is Executed :
When the applet is executed, it is expected that a human face is drawn.
1. Initially, set the background color of frame as white.
2. Create a color which is similar to the human skin color, and then draw and fill the outer boundary of the face.
3. Then set the color to black.
4. Draw and fill the left eye and the right eye.
5. Draw the right eyebrow and the left eyebrow.
6. Draw the nose.
7. Draw the smile.
Here is source code of the Java Program to draw a human face using applet. The program is successfully compiled and tested using javac compiler on Fedora 30. The program output is also shown below.
/*Java Program to Draw a Human Face using Applet*/
import java.applet.*;
import java.awt.*;
public class Human_Face extends Applet
{
//Initialize the applet
public void init()
{
setBackground(Color.white);
}
//Draw the human face
public void paint(Graphics g)
{
//Change color to cream
Color clr=new Color(255,179,86);
g.setColor(clr);
//Draw and fill the face
g.drawOval(100,100,250,300);
g.fillOval(100,100,250,300);
//Change color to black
g.setColor(Color.black);
//Draw the left eye
g.drawOval(160,185,40,25);
g.fillOval(160,185,40,25);
//Draw the right eye
g.drawOval(250,185,40,25);
g.fillOval(250,185,40,25);
//Draw the Left Eyebrow
g.drawArc(160,170,35,10,0,180);
//Draw the Right Eyebrow
g.drawArc(250,170,35,10,0,180);
//Draw the Nose
g.drawLine(210,265,210,275);
g.drawLine(240,265,240,275);
g.drawArc(210,275,30,10,0,-180);
//Draw the smile
g.drawArc(175,300,100,50,0,-180);
}
}
/*
<applet code = Human_Face.class width=500 height=500>
</applet>
*/
To execute the applet use the following commands:
>>>javac Human_Face.java >>>appletviewer Human_Face.java
1. The RGB value (255,179,86) gives a kind of human skin color. Create a color using this value.
2. To draw and fill the face and eyes use drawOval and fillOval respectively.
3. To draw the eyebrows and smile use drawArc.
4. To draw the nose use drawArc and drawLine.
Here’s the run time test cases for drawing human face using an applet.
Test case 1 – To view the Human Face in an Applet.
Sanfoundry Global Education & Learning Series – Java Programs.
- Apply for Java Internship
- Practice Information Technology MCQs
- Check Programming Books
- Practice BCA MCQs
- Check Java Books