Proxy > Gmail Facebook Yahoo!

Applet to make a smiley face



In this applet, we’ll be making a face using different shapes. The applet package contains methods to draw an Oval, a line, rectangle, rounded rectangle, arc, etc.
To make a smiley face, we will be using Ovals and arcs.
Syntax for drawing an Oval:
1
obj.drawOval(x,y,width,height);
In the above syntax, drawOval() method needs to be supplied four arguments. The first two arguments to set the position of the oval along the x axis and the y axis and the last two arguments to set the width and height of the oval.
Syntax for drawing an Arc:
1
obj.drawArc(x,y,width,height,starting angle,arc angle);
The drawArc() method needs to be accessed using an object with the dot operator. It needs to be supplied six arguments. The first two arguments to set the position of the arc along the x axis and the y axis and the next two to set the width and height of the arc respectively. The last two arguments determine the starting angle of the arc and angle of the arc.
Difference between drawOval() and fillOval().
‘draw’ is used to draw the outline of the given shape whereas ‘fill’ will fill the shape with the color which is set in the color pallet. To understand the difference properly, please refer the program given below.

import java.applet.*;
import java.awt.*;
public class Smiley extends Applet 
{
 public void paint(Graphics g)
 {
  g.setColor(Color.orange); //Setting color pallet to orange to paint the face
  g.fillOval(50, 50, 75, 75); //Draws Face
  g.setColor(Color.black); //Setting color pallet to black to paint the following shapes
  g.fillOval(65, 65, 15, 15); //Draws left eye
  g.fillOval(95, 65, 15, 15); //Draws right eye
  g.drawOval(90,63,25,25); //Draws  right outer eye
  g.drawOval(60,63,25,25); //Draws left outer eye
  g.drawArc(70, 90, 40,15, 180, 180); //Draws mouth
 }
 
}


Responses

0 Respones to "Applet to make a smiley face"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar