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
- Different colors each time
- Have it say below the five people
- Repeat 5 times There are 5 people living in the house
- Create an octagon w/ a for loop drawing 8 lines.
|