Hi everyone. I'm having some trouble with my assignment. I need to design an applet that draws 5 circles of random radius(between 25-100) and in random locations. Use a width of 400 and height of 300 as the size of the applet.
There are a few things I don't completely understand about the directions. It says a random "radius" between 25-100. the drawOval statement requires a x and y value as the argument to draw the "imaginary" rectangle in which the oval is contained. What exactly do the instructions mean when they say "radius". Also I can't figure out how to size the applet to 400x300.
Below is my code so far. Right now the output is 5 circles that descend from the top/left to bottom/right of the screen. They also increase in size one at a time. So yes, they are not random. What can I use to improve my code? Am I using the random number generator correctly here? Thank you for your help!
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
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();
int random;
int x,y;
int width, height;
setBackground(Color.white);
random=generator.nextInt(80);
page.setColor(Color.black);
x=random;
y=random;
width=random;
height=random;
page.drawOval(x, y, width, height);
random=generator.nextInt(80)+25;
page.setColor(Color.black);
x=random;
y=random;
width=random;
height=random;
page.drawOval(x, y, width, height);
random=generator.nextInt(80)+25;
page.setColor(Color.black);
x=random;
y=random;
width=random;
height=random;
page.drawOval(x, y, width, height);
random=generator.nextInt(80)+25;
page.setColor(Color.black);
x=random;
y=random;
width=random;
height=random;
page.drawOval(x, y, width, height);
random=generator.nextInt(80)+25;
page.setColor(Color.black);
x=random;
y=random;
width=random;
height=random;
page.drawOval(x, y, width, height);
}
}