Birds

<< Morse Code Tone | OtherProjectsTrailIndex | Trig Drill >>

BirdApplet.java

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

public class BirdApplet extends Applet
{
   public void paint(Graphics g)
   {
       Bird p = new Chick(g);
       drawGrid(g);
    }
    public void drawGrid(Graphics g)
    {
         g.setColor(Color.BLACK);
         for(int i=0; i<getWidth();  i+=50)
           for(int j=0; j<getHeight(); j+=50)
             g.drawOval(i,j,2,2);
    }
}

Bird.java

import java.awt.*;
class Bird
{
    private Color myColor;
    public Bird(Graphics g, Color c)
    {
        myColor=c;
        g.setColor(myColor);
        g.fillOval(75,200,400,200);
        g.fillOval(50,150,125,125);
        drawFoot(g, 270, 400);
        drawFoot(g, 300, 400);
        drawEye(g, 75,200);
        drawBeak(g,50, 220);

    }
    public Bird(Graphics g)
    {
        this(g, Color.ORANGE);
    }
    public void drawFoot(Graphics g, int x, int y)
    {
        Polygon foot=new Polygon();
        foot.addPoint(x,y);
        foot.addPoint(x,y+50);
        foot.addPoint(x-20,y+100);
        foot.addPoint(x,y+100);
        foot.addPoint(x+20,y+50);
        foot.addPoint(x+20,y+100);
        foot.addPoint(x+20,y);
        g.fillPolygon(foot);
    }
    public void drawEye(Graphics g, int x, int y)
    {
        g.setColor(Color.WHITE);
        g.fillOval(x,y,20,20);
        g.setColor(Color.BLACK);
        g.fillOval(x+2,y+10,10,10);
    }
    public void drawBeak(Graphics g, int x, int y)
    {
        g.setColor(Color.RED);
        Polygon beak = new Polygon();
        beak.addPoint(x,y);
        beak.addPoint(x-25,y+50);
        beak.addPoint(x+15,y+30);
        g.fillPolygon(beak);
    }
}

Chick.java

import java.awt.*;
class Chick extends Bird
{
    public Chick(Graphics g)
    {
        super(g, Color.YELLOW);
    }
    public void drawBeak(Graphics g, int x, int y)
    {
        g.setColor(Color.ORANGE);
        Polygon beak = new Polygon();
        beak.addPoint(x,y);
        beak.addPoint(x-20,y+10);
        beak.addPoint(x-10,y+20);
        beak.addPoint(x-15,y+30);
        beak.addPoint(x+5,y+20);
        g.fillPolygon(beak);
    }
}