This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Translate a circle component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Translate a circle component" Watch "Translate a circle component" New topic
Author

Translate a circle component

tom davies
Ranch Hand

Joined: Apr 27, 2012
Posts: 168
I am trying to centre a circle component i have created. I think my method of calculating the correct co ordinates is right, but when i try to translate using the new co ordinates i get an error saying
cannot find symbol
symbol: Method translate(double,double)
location: variable circle of type Double

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14117
    
  16

Your variable circle has the type java.awt.geom.Ellipse2D.Double. When I look that class up in the API documentation, I don't see that it has a method translate(). The compiler is complaining that that method doesn't exist.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

There is not method translate for the type you are using, hence the error.
You can first calculate the position where your ellipse is to be drawn and then draw it (no need for changing). By the way, the code for calculating y coordinate of the center is not correct.


The quieter you are, the more you are able to hear.
tom davies
Ranch Hand

Joined: Apr 27, 2012
Posts: 168
Thanks, had a re-think and decided to make the height/width a percentage of the JComponent size.
Is this the most efficient way to do it or have i made more work for myself than needed?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38513
    
  23
I shall move you to our GUIs forum.
There is in fact an object around which has a translate() method, but it aint’t the circle. It’s the Graphics object. Look here and search/Google for affine transforms. I suggest you copy the Graphics object; some affine transforms can alter the object in such a way that you can never return it to its original state. You also need to cast it to Graphics2D. Something like this might work.Read the documentation carefully; that doesn’t mean 12 right and 34 up.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Translate a circle component