Saturday 10 December 2011

Human face or Smiley program in java using Applet


import java.awt.*;
import java.applet.*;


public class HumanFace extends Applet{
private int mouseX, mouseY;
private boolean mouseclicked = false;
public void init(){
setBackground(Color.GREEN);
}


public void paint(Graphics g)
{
g.setColor(Color.YELLOW);
g.fillOval(40,40,120,150);
g.setColor(Color.BLACK);
g.drawOval(57,75,30,30);
g.drawOval(110,75,30,30);
g.fillOval(68,81,10,10);
g.fillOval(121,81,10,10);
g.setColor(Color.RED);
g.drawLine(100,100,100,130);
g.fillRect(75,140,50,7);
if (mouseclicked) {
g.clearRect(75,140,50,7);
g.setColor(Color.BLUE);
g.fillRect(70,139,60,9);
//g.drawArc(40,100,100,50,0,-120);
mouseclicked = true;
}


}


public boolean mouseDown(Event e, int x, int y )
{
mouseX=x; mouseY=y;
mouseclicked = true;
repaint();
return true;
}
}
/* <applet code="HumanFace.class" height= "300" width="200" >
</applet> */


//Output look like this...



1 comment:

  1. import java.applet.*;
    import java.awt.*;

    public class Main extends Applet
    {
    public void paint (Graphics g)
    {

    setBackground(Color.DARK_GRAY);

    g.setColor(Color.yellow);
    g.fillOval(65, 65, 125, 125);
    g.setColor(Color.BLACK);
    g.fillOval(135, 101, 20, 20);
    g.fillOval(95, 101, 20, 20);
    g.drawArc(100, 140, 50,25, 180, 180);

    }
    }

    ReplyDelete