Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a decent looking Circle in Java

I have tried using the method drawOval with equal height and width but as the diameter increases the circle becomes worse looking. What can I do to have a decent looking circle no matter the size. How would I implement anti-aliasing in java or some other method.

like image 749
Bobby Avatar asked Jul 07 '09 20:07

Bobby


People also ask

Can Java do Graphics?

There are several ways to create graphics in Java; the simplest way is to use java. awt. Canvas and java. awt.

How do you draw an oval in Java?

drawOval(int x,int y,int height, int width); This method will draw an oval at specified x and y position with given height and width. g2. fillOval(int x,int y,int height, int width); This method will fill an oval at specified x and y position with given height and width.


1 Answers

As it turns out, Java2D (which I'm assuming is what you're using) is already pretty good at this! There's a decent tutorial here: http://www.javaworld.com/javaworld/jw-08-1998/jw-08-media.html

The important line is:

graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,                           RenderingHints.VALUE_ANTIALIAS_ON); 
like image 83
Brandon Yarbrough Avatar answered Sep 19 '22 04:09

Brandon Yarbrough