Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Whats the error in my program-creating overlapping GOval objectsusing GraphicsProgram

Reply
Thread Tools

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

 
 
student
Guest
Posts: n/a
 
      01-21-2012
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;

}
}
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      01-21-2012
student <(E-Mail Removed)> writes:
>concentric..they appear to be pushed off on the sides of each other as


http://jtf.acm.org/javadoc/student/a...uble,%20double)

 
Reply With Quote
 
 
 
 
Jeff Higgins
Guest
Posts: n/a
 
      01-21-2012
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,%20dou ble)>

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;
>
> }
> }


 
Reply With Quote
 
Rajiv Gupta
Guest
Posts: n/a
 
      01-21-2012
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.

 
Reply With Quote
 
student
Guest
Posts: n/a
 
      01-21-2012
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".
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-21-2012
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/wikipedi.../c/cf/Friz.jpg
 
Reply With Quote
 
Jeff Higgins
Guest
Posts: n/a
 
      01-21-2012
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.
 
Reply With Quote
 
student
Guest
Posts: n/a
 
      01-22-2012
On Jan 21, 2:51*am, Jeff Higgins <(E-Mail Removed)> 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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to "force" my object never been changed by other other objectsusing it? Chris Dollin Java 8 02-08-2007 05:42 PM
IOS: IPSec between overlapping subnets Oleg Tipisov Cisco 1 08-10-2004 12:35 PM
PIX: IPSec between overlapping subnets and "dns" keyword Oleg Tipisov Cisco 0 08-10-2004 08:29 AM
regexp to list all sentences and sub sentences, with overlapping? Tony Perl 4 11-27-2003 01:38 PM
Pix 506e, VPN, and overlapping pools... a love story Nate Smith Cisco 2 10-21-2003 03:38 PM



Advertisments