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

Discussion in 'Java' started by student, Jan 21, 2012.

  1. student

    student Guest

    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;

    }
    }
    student, Jan 21, 2012
    #1
    1. Advertising

  2. student

    Stefan Ram Guest

    Stefan Ram, Jan 21, 2012
    #2
    1. Advertising

  3. student

    Jeff Higgins Guest

    On 01/20/2012 08:05 PM, student wrote:
    > 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.


    Reread the GOval documentation.
    <http://jtf.acm.org/javadoc/student/acm/graphics/GOval.html#GOval(double,%20double,%20double,%20double)>

    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;
    >
    > }
    > }
    Jeff Higgins, Jan 21, 2012
    #3
  4. student

    Rajiv Gupta Guest

    Re: Whats the error in my program-creating overlapping GOval objects using GraphicsProgram

    On 2012-01-21 12:05:14 +1100, student said:

    > 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.
    Rajiv Gupta, Jan 21, 2012
    #4
  5. student

    student Guest

    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".
    student, Jan 21, 2012
    #5
  6. student

    Lew Guest

    On 01/20/2012 10:19 PM, student wrote:
    > 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?

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, Jan 21, 2012
    #6
  7. student

    Jeff Higgins Guest

    On 01/21/2012 01:19 AM, student wrote:
    > 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.
    Jeff Higgins, Jan 21, 2012
    #7
  8. student

    student Guest

    On Jan 21, 2:51 am, Jeff Higgins <> wrote:
    > On 01/21/2012 01:19 AM, student wrote:> 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.


    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!
    student, Jan 22, 2012
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony
    Replies:
    4
    Views:
    2,137
    Andy De Petter
    Nov 27, 2003
  2. Harry Whitehouse
    Replies:
    3
    Views:
    436
    Harry Whitehouse
    Jul 22, 2003
  3. mark

    overlapping datagrids

    mark, Mar 3, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    361
    Chris Jackson
    Mar 5, 2004
  4. =?Utf-8?B?RmFoYWQgQWlqYXo=?=

    Overlapping Images in ASP.NET

    =?Utf-8?B?RmFoYWQgQWlqYXo=?=, Dec 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,327
    Kevin Spencer
    Dec 7, 2004
  5. Chris Dollin
    Replies:
    8
    Views:
    350
    Eric Sosman
    Feb 8, 2007
Loading...

Share This Page