# Need help with fillArc()

• February 2nd, 2011, 09:05 AM
dunnkers
[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%
http://img708.imageshack.us/img708/4297/56408974.png

75%
http://img265.imageshack.us/img265/7092/51827154.png

How would i do this with fillArc()?

I draw the background:
Code :

` g.drawOval(0, 0, 100, 100);`
I can fill half the oval:
Code :

` 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
http://img39.imageshack.us/img39/9744/70654879.png

Thanks, Dunnkers.
• February 2nd, 2011, 09:33 AM
copeg
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
• February 2nd, 2011, 09:34 AM
KevinWorkman
Re: Need help with fillArc()
This thread has been cross posted here:

Java Programming Forums Cross Posting Rules

The Problems With Cross Posting

• February 2nd, 2011, 09:54 AM
dunnkers
Re: Need help with fillArc()
Quote:

Originally Posted by copeg
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%

Quote:

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

Java Programming Forums Cross Posting Rules

The Problems With Cross Posting

Sorry for the crosspost.
• February 2nd, 2011, 09:57 AM
copeg
Re: Need help with fillArc()
Quote:

How would i stroke the oval?
Read the API for Graphics, in particular the *Oval methods
• February 2nd, 2011, 10:17 AM
dunnkers
Re: Need help with fillArc()
I still have no idea how i would do this, could someone give me an example?
• February 2nd, 2011, 11:15 AM
copeg
Re: Need help with fillArc()
Quote:

Originally Posted by dunnkers
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.
• February 2nd, 2011, 11:44 AM
dunnkers
Re: Need help with fillArc()
Quote:

Originally Posted by copeg
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)

http://img560.imageshack.us/img560/1725/117t.png

Code :

``` 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.
• February 2nd, 2011, 12:01 PM
dunnkers
Re: Need help with fillArc()
I crossposted this on yet another forum, (i really needed an answer) and the answer has been found.
• February 2nd, 2011, 12:14 PM
copeg
Re: Need help with fillArc()
Quote:

Originally Posted by dunnkers
I crossposted this on yet another forum, (i really needed an answer) and the answer has been found.