The personApplet
/*
An applet that demonstrates the use of methods.
We will write a method, called drawPerson, that given the x and y
coordinates of an anchor point, and a height in pixels, it draws
a stick figure anchored at that point.
The x and y coordinates specify the anchor point as the point between
the legs at the bottom.
*/
import java.awt.*;
import java.applet.Applet;
public class personApplet extends Applet {
public void init() {
// nothing to do here
} // end of init
public void paint(Graphics g) {
// draw some people!
g.setColor(Color.red);
drawPerson(g, 50, 380, 200);
g.setColor(Color.cyan);
drawPerson(g, 100, 380, 200);
g.setColor(Color.blue);
drawPerson(g, 150, 380, 300);
} // end of paint
private void drawPerson(Graphics g, int x, int y, int h) {
// Draw head (about a 1/4 of the height in proportion)
g.fillOval(x-h/8, y-h, h/4, h/4);
// Draw body
g.drawLine(x, y-3*h/4, x, y - h/4);
// Draw legs
g.drawLine(x, y-h/4, x-h/8, y);
g.drawLine(x, y-h/4, x+h/8, y);
// Draw arms
g.drawLine(x, y-5*h/8, x-h/8, y-3*h/4);
g.drawLine(x, y-5*h/8, x+h/8, y-3*h/4);
} // end of drawPerson
} // end of personApplet