Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Drawing circles with smoother lines?

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Drawing circles with smoother lines?

    hiya,
    just like to get some information on drawing circles.
    the output from the code below displays a circle but the lines are broken.

    thanks

    import java.awt.*;
    import javax.swing.*;
    import java.applet.*;
     
    public class Circles extends JApplet
    {
    	public void init()
    	{
     
    	}
    	public void paint(Graphics g)
    	{
    		g.drawOval(10, 10, 100, 100);
    	}
    }


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Drawing circles with smoother lines?

    -- Cast the Graphics to Graphics2D :
    Graphics2D g2 = (Graphics2D) g;
    -- set the rendering hint:
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    db

  3. The Following User Says Thank You to Darryl.Burke For This Useful Post:

    tabutcher (April 17th, 2010)

  4. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Drawing circles with smoother lines?

    At a certain point, there's really no way to get a "smoother" circle because computer displays can only display rasterized images. The only way to get a smoother circle is to increase the canvas size that the circle is being drawn to. Anti-aliasing can help, but at some point it will stop working.

  5. The Following User Says Thank You to helloworld922 For This Useful Post:

    tabutcher (April 17th, 2010)

  6. #4
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    495
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Drawing circles with smoother lines?

    Anti-aliasing doesn't "stop working". It's a trade-off of sharpness for smoothness.

    db

  7. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Drawing circles with smoother lines?

    True, maybe I should have said becomes less effective

    Trying to anti-alias a circle 2x2 pixels will only make the square draw lighter

Similar Threads

  1. Replies: 4
    Last Post: July 20th, 2010, 07:15 AM
  2. [SOLVED] reading only certain lines from a .txt file
    By straw in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 7th, 2010, 06:49 PM
  3. keeping an drawing centered in Graphics
    By dvsumosize in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 27th, 2010, 10:26 PM
  4. [SOLVED] Supressing empty lines and does not do until the end! Why ?
    By lumpy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 18th, 2010, 06:38 AM
  5. Drawing image on JPanel from another frame
    By jeryslo in forum AWT / Java Swing
    Replies: 3
    Last Post: December 8th, 2009, 03:01 PM