Saturday, February 21, 2026
HomeLanguagesJavaDraw a Smiley in Java Applet

Draw a Smiley in Java Applet

Given task is to draw a smiley face in Java Applet.
Approach: 
 

  1. Create three Ovals, one for the face, two for the eyes.
  2. Fill eyes oval with black color.
  3. Create an arc for the smile in the face.

Below is the implementation of the above approach:
Applet Program:
 

Java




// Java program to Draw a
// Smiley using Java Applet
import java.applet.*;
import java.awt.*;
/*<applet code ="Smiley" width=600 height=600>
</applet>*/
 
public class Smiley extends Applet {
    public void paint(Graphics g)
    {
 
        // Oval for face outline
        g.drawOval(80, 70, 150, 150);
 
        // 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);
    }
}


Output: 
 

Note: To run the applet in command line use the following commands 
 

> javac Smiley.java
> appletviewer Smiley.java

You can also refer https://www.geeksforgeeks.org/different-ways-to-run-applet-in-java to run applet program .
 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS