' Java Applet Program to Draw a Smiley Face | Infolet

Java Applet Program to Draw a Smiley Face



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



Responses

0 Respones to "Java Applet Program to Draw a Smiley Face"

Post a Comment

 

Free Updates

Enter your email address:

Delivered by FeedBurner

Learn C

About Author

Author of infolet.org
Muhammed Aslam PK, He is a MCA(Master of Computer Applications) student. See More here
Contact Us
Return to top of page Copyright © 2010 | Infolet.org Google Converted into Blogger Template by HackTutors