I need to create a class that represents one crayon of a particular color and height(length). Then, I need to design an applet that lets me draw a box of different colored crayons.
This is what I have so far:
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)
{
page.setColor (color);
page.fillRect (location, BOTTOM - length, WIDTH, length);
}
}
AND OBJECT/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)
{
setBackground (Color.white);
setSize (APPLET_WIDTH, APPLET_HEIGHT);
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);
page.setColor (Color.black);
page.drawString ("Crayola", 150, 200);
}
}
However, the yellow box is being drawn but not the crayons. PLEASE HELP!!