Concentric circles questions. For some reason, center is not on same dimension
Hi, I designed this code, but I cannot put all of the circles on same
center. I think they are on different dimensions, what do you think?
/* Concentric.java
Design and implement a program that draws 10 concentric circles of
random radius.
*/
import javax.swing.JFrame;
public class Concentric
{
public static void main (String[] args)
{
JFrame frame = new JFrame ("Concentric");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new CirclePanel());
frame.pack();
frame.setVisible(true);
}
}
//CirclePanel
import javax.swing.JPanel;
import java.awt.*;
import java.util.Random;
public class CirclePanel extends JPanel
{
public CirclePanel()
{
setPreferredSize (new Dimension(300,300));
setBackground (Color.white);
}
public void paintComponent(Graphics page)
{
super.paintComponent (page);
int x = 0, y = 0;
int diameter;
page.setColor (Color.white);
for (int count = 0; count <10; count++)
{
Random generator = new Random();
diameter = generator.nextInt(150)+5;
page.setColor (Color.black);
page.drawOval (x, y, diameter, diameter);
}
}
}