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 11 of 11

Thread: Need help with fillArc()

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool [SOLVED] Need help with fillArc()

    I want to create some sort of progress circle like this:
    (I made these in paint, not in java)

    25%


    75%


    How would i do this with fillArc()?


    What i already have:
    I draw the background:
    		g.drawOval(0, 0, 100, 100);
    I can fill half the oval:
    		g.fillArc(0, 0, 100, 100, 0, -180);


    How fillArc works:
    fillArc(x, y, width, height, startAngle, angle);
    - 3 o'clock is 0
    - positive values go clockwise, negative values go counter clockwise


    Thanks, Dunnkers.
    Last edited by dunnkers; February 2nd, 2011 at 01:03 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Need help with fillArc()

    1) Fill a complete oval
    2) Fill a rectangle (color set to background) covering the percentage of the oval you wish to cover based upon progress.
    3) Stroke the oval

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Need help with fillArc()

    This thread has been cross posted here:

    http://www.java-forums.org/java-2d/38258-need-help-fillarc.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with fillArc()

    Quote Originally Posted by copeg View Post
    1) Fill a complete oval
    2) Fill a rectangle (color set to background) covering the percentage of the oval you wish to cover based upon progress.
    3) Stroke the oval
    How would i stroke the oval?
    Let's say the percentage is 25%

    Thanks for your reply


    Quote Originally Posted by KevinWorkman View Post
    This thread has been cross posted here:

    http://www.java-forums.org/java-2d/38258-need-help-fillarc.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    Sorry for the crosspost.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Need help with fillArc()

    How would i stroke the oval?
    Read the API for Graphics, in particular the *Oval methods

  6. #6
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with fillArc()

    I still have no idea how i would do this, could someone give me an example?

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Need help with fillArc()

    Quote Originally Posted by dunnkers View Post
    I still have no idea how i would do this, could someone give me an example?
    I gave you step by step instructions above...you have to tell us what exactly you don't understand about them for anyone to help you further, or better yet give it a try, read the API for Graphics and look for useful methods, and post some code demonstrating what you've attempted and what the problem is.

  8. #8
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with fillArc()

    Quote Originally Posted by copeg View Post
    I gave you step by step instructions above...you have to tell us what exactly you don't understand about them for anyone to help you further, or better yet give it a try, read the API for Graphics and look for useful methods, and post some code demonstrating what you've attempted and what the problem is.
    Okay, sorry for my un-constructive post.

    What i managed to do:
    (The picture is taken from a java applet)



    				int x = 10, y = 10;
    				int width = 100, height = 100;
     
    				g.setColor(Color.BLACK);
    				g.drawRect(x, y, width, height);
     
    				g.setColor(setAlpha(Color.RED, 150));
    				g.fillOval(x, y, width, height);
     
    				//the calculations of the arc start here
    				int x_ = (int) (x+((width*0.25)/2));
    				int y_ = y+height_;
    				int width_ = width-((x_-x)*2);
    				int height_ = (int) (height*(0.25*2));
     
    				g.setColor(Color.BLACK);
    				g.drawRect(x_, y_, width_, height_);
     
    				g.setColor(setAlpha(Color.GREEN, 150));
    				g.fillArc(x_, y_, width_, height_, 0, -180);

    The problem: It doesn't yet fit perfectly. The missing calculation. I don't how.
    Last edited by dunnkers; February 2nd, 2011 at 12:46 PM.

  9. #9
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with fillArc()

    I crossposted this on yet another forum, (i really needed an answer) and the answer has been found.
    Link: Need help with fillArc()

  10. #10
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    183
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Need help with fillArc()

    Quote Originally Posted by dunnkers View Post
    I crossposted this on yet another forum, (i really needed an answer) and the answer has been found.
    Link: Need help with fillArc()
    Well then, good for you that you found an answer, bad for you that you were spoonfed, and bad for me that I wasted my time trying to help you. Thanks for that. Perhaps you should read: The problems with crossposting...and for what its worth, that solution is beyond overkill

  11. #11
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help with fillArc()

    I read and i understand now. I will not crosspost anymore.
    I thought i'd get an answer sooner, but actually the time explaining mutliple people the same problem, cost me more time.

    Thanks for your help though, copeg.