email me at borlaj@portlandschools.org

Loading
notes previous (10/<10) submit the dump links  
 

HWJ7

Applet - 5 People

More work with loops. -

Using 1 loop to draw 5 people next to each other. Create a basic applet and edit the paint method to have a loop that will draw the people. Links to methods for graphics are here.

If you want to start with code, start with below:

import java.awt.*;
import java.applet.*; 
/**
 * Class Five People - This applet draws 5 people
 * 
 * @author (your name) 
 * @version (a version number)
 */

public class HWJ7 extends Applet
{
	
	/**
	 * Paint method for applet.
	 * 
	 * @param  g   the Graphics object for this applet
	 */
	public void paint(Graphics g)
	{
		// simple text displayed on applet
		g.setColor(Color.white);
		g.fillRect(0, 0, 200, 100);
		g.setColor(Color.black);
		g.drawString("Sample Applet", 20, 20);
		g.setColor(Color.blue);
		g.drawString("created by BlueJ", 20, 40);
	}

}			
			

Challenge:

Extend above adding

  1. Different colors each time
  2. Have it say below the five people
    1. Repeat 5 times There are 5 people living in the house
  3. Create an octagon w/ a for loop drawing 8 lines.