Here is my draw method from my
But I cannot figure out how to call the draw method. Thank you for the help in advance.
Code:
Crayon class:
public void draw (Graphics screen, int x, int y) {
screen.setColor(crayonColor);
int xcoords [] = {x+50,x+25,x+150,x+150,x+50};
int ycoords [] = {y+50,y+0,y+50,y+550,y+550};
screen.fillPolygon(xcoords,ycoords,5);
}
The applet I'm making is supposed to draw 8 crayons with a random color and different heights. Here is my code so far:
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class TestCrayon extends JApplet{
public void paint (Graphics page){
//random color
int r = (int)(Math.random()*(255-0+1)+1);
int g = (int)(Math.random()*(255-0+1)+1);
int b = (int)(Math.random()*(255-0+1)+1);
Color col = new Color(r, g, b);
//create crayon object
Crayon one = new Crayon(col,200);
one.draw();
}
}
Comment