Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Graphics2D drawOval(int,int,int,int) method  RSS feed

 
joew weakers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. I am trying to draw a simple circle/oval to reperesent how a point object, e.g. shop, appears in a map legend. I am adding the object to a JPanel upon which the map legend has been created. The problem is that I am having real difficulty determining what int parameters to assign in order to draw the best possible oval, i.e. closest to a perfect circle. Every time I play around with the parameters I keep drawing weird looking shapes that do not look anywhere near circular in shape. Has anybody any ideas. My code looks as follows:



Thanks a lot, Joe
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do your shapes look like then? The second two parameters to the fillOval are the width and the height of a rectangle that would contain the oval. So if you make these two parameters the same, you should have a circle whose diameter is the value you specificed.

So this will draw a circle whose top left corner is at (0,0), and which has a diameter of 100 pixels:

Note also that you do not need to call drawOval and fillOval. fillOval alone will do what you want.
 
joew weakers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Stuart. Everything looks fine now. Joe
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!