Calling a draw method from another class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Volantvirus
    New Member
    • Sep 2014
    • 1

    Calling a draw method from another class

    Here is my draw method from my
    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();
               
          }
          }
    But I cannot figure out how to call the draw method. Thank you for the help in advance.
    Last edited by Rabbit; Oct 1 '14, 12:16 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    You are calling "one.draw() ", but do not pass any parameters the method needs. Passing poarameters means for example calling "one.draw(g , 100, 100);". Where g is an instance of Graphics class. If you do not have this instance, just create it with "Graphics g = new Graphics(<param eters>)".

    Comment

    Working...