Whats the error in my program-creating overlapping GOval objectsusing GraphicsProgram

S

student

I am trying to create three concentric circles of different color
using GraphicsProgram. However the circles never appear to be
concentric..they appear to be pushed off on the sides of each other as
if trying to show another dimension. I am simply creating and adding
the GOval objects. May be I am missing something. Is there a way to
set transparency of the circles?

Adding code below:

import acm.graphics.*;
import acm.program.*;
import java.awt.*;

public class Target extends GraphicsProgram {

final static double radiusOuterCircle = 72.0;
final static double radiusMiddleCircle = 47.0;
final static double radiusInnerCircle = 22.0;


public void run() {


final double centerX = this.getWidth() / 2.0;
final double centerY = this.getHeight() / 2.0;


GOval g = makeCircle(centerX, centerY,radiusOuterCircle ,
Color.RED);
add(g);


g = makeCircle(centerX, centerY,radiusMiddleCircle ,
Color.WHITE);
add(g);


g = makeCircle(centerX, centerY,radiusInnerCircle ,
Color.RED);
add(g);


}



private GOval makeCircle(double centerX, double centerY, double
radius, Color color)
{

GOval g = new GOval(centerX, centerY, radius, radius);
g.setFillColor(color);
g.setFilled(true);

return g;

}
}
 
R

Rajiv Gupta

I am trying to create three concentric circles of different color
using GraphicsProgram. However the circles never appear to be
concentric..they appear to be pushed off on the sides of each other as
if trying to show another dimension. I am simply creating and adding
the GOval objects. May be I am missing something. Is there a way to
set transparency of the circles?

You probably have an uncaught overlapped circle exception.
 
S

student

I read the documentation. How do I create concentric circles? I am not
able to understand. I want to create sign like the sign of national
chain of stores "Target".
 
L

Lew

I read the documentation. How do I create concentric circles? I am not

By drawing them in such a fashion that they have the same center.
able to understand. I want to create sign like the sign of national
chain of stores "Target".

Think about how you line them up given the documentation. What conditions
would have to hold in the constructor arguments for the circles' centers to be
the same? What algebraic transformation do you have to perform?

To put it another way: What data does the constructor require to position a
circle in a particular place? What data do you have available at the point of
the constructor call? What formula transforms the latter to the former?
 
J

Jeff Higgins

I read the documentation. How do I create concentric circles? I am not
able to understand. I want to create sign like the sign of national
chain of stores "Target".
It might help you to visualize the problem.
Attempt to place a GRect centered upon centerX, centerY.
 
S

student

On 01/21/2012 01:19 AM, student wrote:> I read the documentation. How do I create concentric circles? I am not

It might help you to visualize the problem.
Attempt to place a GRect centered upon centerX, centerY.

You are right, there is a bug in my code. I am not sending the upper
left hand corner coordinates of the bounding rectangle in makeCircle()
in the call to GOval. These coordinates will vary for all three circle
because they have different radii. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top