I need to call a draw method that takes a graphics object as its parameter, but do not know how I can do that. Here's my code:
public static class Circle //Class that takes in x and y coordinates and radius and creates and draws a circle
public int xPos;
public int yPos;
public int red;
public int green;
public int blue;
public Color circleFill;
public Circle(int xin, int yin, double radius)
xPos = xin;
yPos = yin;
red = (int)Math.random()*255; //// ////
green = (int)Math.random()*255; // Generates random colors to fill circle //
blue = (int)Math.random()*255; //// ////
circleFill = new Color(red, green, blue);
//-->Call draw method??
public void draw(Graphics g) //Method takes a graphics object?? How to pass that in?
g.fillOval(xPos, yPos, radius, radius);
it is from within your 'paintComponent(Graphics g)' that you should invoke 'circle.draw(g)',
where 'circle' is an instance of your Circle class. The 'paintComponent' should be in the
JPanel that you use for these drawings.
So, for instance, in your JPanel you have
There are three kinds of actuaries: those who can count, and those who can't.