• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Translate a circle component

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
tom davies
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
This tiny ad will self destruct in five seconds.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic