Press "Enter" to skip to content

Draw a Smiley Human Face in Java Applet

Java Applet Program to Draw a Smiley Face

 
We can make any type of smileys face by Java applet program codes. This java program shows how to make a normal human smiley face icon. But these are not similar to original smileys. But by doing this type of Java Applet programs, you can familiarize to X,Y coordinate of graphics.

import java.applet.*;import java.awt.*;
 /* <applet code = "face" width = 300 height = 300> </applet> */
public class face extends Applet
{ 
public void paint(Graphics g) 
 {      
    g.drawOval(100,100,100,100);      
    g.fillOval(120,125,20,20);      
    g.fillOval(160,125,20,20);     
    g.drawLine(150,165,150,150);      
    g.drawLine(130,170,170,170);   
 }
} 

If you compile and run above code, you will get out put like below. Like this you can make different type of smileys. (Learn here how to make and run a Java Applet Program )

Java Applet Program to Draw a human Smiley Face

Here drowOval (or drawAnyshape) indicate oval without any inner color, and fillOval (or fillAnyshape) indicate color filled oval.

You can declare the color in variable ‘g’. Example: g.setColor(Color.yellow);

Then all color using ‘g’ should be ‘yellow’ until setting a new color.

Colorful smiley:         

import java.applet.*;
import java.awt.*;
/* <applet code = "face" width = 300 height = 300> </applet> */
public class face extends Applet
{
public void paint(Graphics g)
   {
    g.setColor (Color.yellow);
    g.fillOval (100,100,100,100);
    g.setColor (Color.black);
    g.fillOval (120,125,20,20);
    g.fillOval (160,125,20,20);
    g.setColor (Color.blue);
    g.drawLine (150,165,150,150);
    g.drawLine (130,170,170,170);
   }
} 

Output:

color colorful human smiley java applet code

Another smiley:

import java.applet.*;
import java.awt.*;
/* <applet code = "face" width = 300 height = 300> </applet> */
public class face extends Applet
{
public void paint(Graphics g)
   {
    g.setColor (Color.yellow);
    g.fillOval (100,100,100,100);
    g.setColor (Color.black);
    g.fillRect (120,125,20,20);
    g.fillRect (160,125,20,20);
    g.drawLine (135,135,160,135);
    g.setColor (Color.red);
    g.drawLine (150,165,150,150);
    g.drawLine (130,170,170,170);
   }
} 

Output:

crazy freak glass smiley applet java code

Another one:

import java.applet.*;
import java.awt.*;
/* <applet code = "face" width = 300 height = 300> </applet> */
public class face extends Applet
{
public void paint(Graphics g)
 {
   g.setColor (Color.yellow);
   g.fillOval (100,100,100,100);
   g.setColor (Color.black);
   g.fillOval (120,125,20,30);
   g.fillOval (160,125,20,30);
   g.setColor (Color.black);
   g.drawLine (150,165,150,150);
   g.setColor (Color.red);
   g.fillRect (130,170,40,10);
   g.setColor (Color.black);
   g.drawLine (131,174,169,174);
 }
} 

Output:

java code applet smiley human color face

One Comment

  1. Education XMC Education XMC 26th January 2021

    This is a interesting article by the way. I am going to go ahead and save this article for my sis to read later on tomorrow. Keep up the first-rate work.

Leave a Reply