FileDocCategorySizeDatePackage
DrawCrowd.javaAPI DocExample1343Wed Jan 09 13:47:28 GMT 2002None

DrawCrowd.java

// Program to demonstrate use of separate class for repetitive code
// Potential customers York City and Sheffield United
// J Harvey 2002

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class DrawCrowd extends Applet
{
	
	Man M1, M2, M3;
	int row, col;
	
	public void init()
	{
		M1=new Man();
	}
	
	public void paint(Graphics g)
	{
		for (col=0; col< 500; col+=50)
			for (row=0; row <400; row+=100)
			{
			M1.drawMan(col,row); // at the moment we simply supply
			//M1.drawMan(150,150); // parameters for position, but could 
			//M1.drawMan(220,75);  // adapt to include size & colour
			}
	}
public class Man
{
	private Graphics gfx;
	
	public Man()
	{
		
		gfx=getGraphics();
		
	}
	
	public void drawMan(int topX, int topY)
	{
		gfx.setColor(Color.red);
		gfx.fillOval(topX, topY, 40,40); 		// head
		gfx.setColor(Color.blue);
		gfx.fillOval(topX+10, topY+10, 4,4);	// eyes
		gfx.fillOval(topX+30, topY+10, 4,4);
		gfx.setColor(Color.yellow);
		gfx.fillRect(topX,topY+40,40,40);		// body
		gfx.setColor(Color.black);
		gfx.fillRect(topX-5, topY+40, 5, 43);	// arms	
		gfx.fillRect(topX+40, topY+40, 5, 43);	
		gfx.fillRect(topX, topY+80, 5, 50);		// legs	
		gfx.fillRect(topX+35, topY+80, 5, 50);	
	
	}
	
	
} // end class Man
		
	
} // end DrawCrowd