I have to do a project where the imust create a class that draws a crayon and then an applet that draws a box of those crayons. I can get the box to draw, just not the crayons. Help?
CLASS
import java.awt.*;
public class Crayon
{
private final int BOTTOM = 150;
private final int WIDTH = 25;
private Color color;
private int length, location;
//----------------------------------------------------------------------------------------------
// Crayon's characteristics.
//----------------------------------------------------------------------------------------------
public Crayon (Color color, int length, int position)
{
color = color;
length = length;
location = position;
}
//----------------------------------------------------------------------------------------------
// Draws crayon.
//----------------------------------------------------------------------------------------------
public void draw (Graphics page)
{
System.out.println();
page.setColor (color);
page.fillRect (location, BOTTOM - length, WIDTH, length);
}
}
APPLET
import java.awt.*;
import java.applet.*;
public class BoxOfCrayons extends Applet
{
private final int APPLET_WIDTH = 350;
private final int APPLET_HEIGHT = 300;
Crayon c1 = new Crayon (Color.cyan, 100, 50);
Crayon c2 = new Crayon (Color.blue, 75, 80);
Crayon c3 = new Crayon (Color.gray, 100, 110);
Crayon c4 = new Crayon (Color.green, 90, 140);
Crayon c5 = new Crayon (Color.magenta, 82, 170);
Crayon c6 = new Crayon (Color.orange, 100, 200);
Crayon c7 = new Crayon (Color.pink, 70, 230);
Crayon c8 = new Crayon (Color.red, 100, 260);
//----------------------------------------------------------------------------------------------
// Draws crayon box.
//----------------------------------------------------------------------------------------------
public void paint (Graphics page)
{
c1.draw (page);
c2.draw (page);
c3.draw (page);
c4.draw (page);
c5.draw (page);
c6.draw (page);
c7.draw (page);
c8.draw (page);
page.setColor (Color.yellow);
page.fillRect (45, 150, 245, 90);
}
}