Draw a Smiley in Java Applet
Last Updated :
11 Mar, 2022
Given task is to draw a smiley face in Java Applet.
Approach:
- Create three Ovals, one for the face, two for the eyes.
- Fill eyes oval with black color.
- Create an arc for the smile in the face.
Below is the implementation of the above approach:
Applet Program:
Java
import java.applet.*;
import java.awt.*;
public class Smiley extends Applet {
public void paint(Graphics g)
{
g.drawOval( 80 , 70 , 150 , 150 );
g.setColor(Color.BLACK);
g.fillOval( 120 , 120 , 15 , 15 );
g.fillOval( 170 , 120 , 15 , 15 );
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 .
Share your thoughts in the comments
Please Login to comment...