Reputation: 59
I am trying to run a program that fills the circles with color I am not sure what I am doing incorrectly I am getting a cannot find symbol error for my fillOval command here is my code. Also the fill should be the same color as the drawn circle.
import javax.swing.JApplet;
import java.awt.*;
import java.util.Random;
public class Drawing extends JApplet
{
public void paint(Graphics page)
{
Random generator=new Random();
float r = generator.nextFloat();
float g = generator.nextFloat();
float b = generator.nextFloat();
Color randomColor = new Color(r, g, b);
int random,randomx,randomy;
int x,y;
int width, height;
setBackground(Color.white);
random=generator.nextInt(24)+8;
randomx=generator.nextInt(24);
randomy=generator.nextInt(24);
x=randomx;
y=randomy;
width=random*2;
height=random*2;
page.drawOval(x, y, width, height);
page.setColor(randomColor);
fillOval(x, y,width,height);
}
}
Upvotes: 1
Views: 5245
Reputation: 285405
Problems:
page
variable.I suggest:
paintComponent(Graphics g)
method.super.paintComponent(g)
, in your paintComponent override method, so that the component does all its housekeeping painting before doing your painting.Upvotes: 2
Reputation: 159754
fillOval
is a method of Graphics
rather than your custom Drawing
class.
fillOval(x, y, width, height);
should be
page.fillOval(x, y, width, height);
Upvotes: 2