# Concentric circle using JPanel

Dj Lee

Greenhorn

Posts: 3

posted 5 years ago

Hello, I'm a beginner in Java and I'm trying to create a jpanel that

creates 10 concentric circles with random radius. But I'm having a bit trouble with it.

Here are my codes:

When I run this, I get only one circle (sometimes none...)

if i set radius = generator.nextInt(MAX_DIAMETER) + 1;

But if i replace MAX_DIAMETER which is 600, to something small maybe 100.

radius = generator.nextInt(100)+1;

than i get 5-10 circles...

What am i doing wrong??

creates 10 concentric circles with random radius. But I'm having a bit trouble with it.

Here are my codes:

When I run this, I get only one circle (sometimes none...)

if i set radius = generator.nextInt(MAX_DIAMETER) + 1;

But if i replace MAX_DIAMETER which is 600, to something small maybe 100.

radius = generator.nextInt(100)+1;

than i get 5-10 circles...

What am i doing wrong??

Dj Lee

Greenhorn

Posts: 3

Debashis jain

Greenhorn

Posts: 3

posted 5 years ago

The radius of the circle is (diameter/2)

"generator.nextInt(MAX_DIAMETER) "when you are using this function that's mean you are expecting a random number from 0-600

so when you write the code diameter=2*radius....actually the diameter at most of the time becomes as big as 1200,and your panel size is (600,600) so it won't suit the created circles.

When I run this, I get only one circle (sometimes none...)

if i set radius = generator.nextInt(MAX_DIAMETER) + 1;

But if i replace MAX_DIAMETER which is 600, to something small maybe 100.

radius = generator.nextInt(100)+1;

than i get 5-10 circles...

What am i doing wrong??

The radius of the circle is (diameter/2)

"generator.nextInt(MAX_DIAMETER) "when you are using this function that's mean you are expecting a random number from 0-600

so when you write the code diameter=2*radius....actually the diameter at most of the time becomes as big as 1200,and your panel size is (600,600) so it won't suit the created circles.

Campbell Ritchie

Marshal

Posts: 52530

119