[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()?
What i already have:
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.
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
Re: Need help with fillArc()
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%
Thanks for your reply
Quote:
Originally Posted by
KevinWorkman
Sorry for the crosspost.
Re: Need help with fillArc()
Quote:
How would i stroke the oval?
Read the API for Graphics, in particular the *Oval methods
Re: Need help with fillArc()
I still have no idea how i would do this, could someone give me an example?
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.
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.
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()
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.
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
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.