hellow,
i wondering will be able to draw a pi chart with diffrent scetions colored diffrently
with out using Graphics2d class....in addition that i want to make it rotating 360 degree.:icon_neutral:

I doubt it very much. Why don't you want to use the one class that was designed for exactly that kind of thing?

ps: If you want to look for sample code etc on Google, the normal spelling is "pie chart"
You will also find packages and products for drawing all kinds of charts.

Sorry my mistake in the header..I did search the Internet but all using graphics 2d
And I want the pie chart to rotate it self...

Any idea of the algorithm.

I don't know how anyone can program that kind of thing without using the Java Graphics classes. Why don't you want to use them?

Member Avatar for hfx642

You can do it using the Graphics class.
You do NOT need to use the Graphcis2D class.
Try using the fillArc() method.
(I was just working on a project to do this yesterday.)

hfx: Graphics is an abstract class. Its only direct subclasses are DebugGraphics and Graphics2D. I doubt that you were working with DebugGraphics q.e.d.
I suspect you were working with a parameter that was declared as Graphics, but the actual instance that was passed to you was an instance of Graphics2D, eg in Swing's paint(Graphics g) or paintComponent(Graphics g) which is why you can cast g to Graphics2D without an error.

ps: Even fillArc is defined as abstract in Graphics; the version you were using must have been the Graphics2D implementation

Member Avatar for hfx642

Well... I don't know how Java works in the background,
but no where in my application do I specify Graphics2D,
and I am using fillArc().
I just know that it works.

That's right, nowhere do you need to mention Graphics2D - but that's how the developers of Swing wrote their code. You declare a Graphics parameter, but they actually give you an instance of Graphics2D, which is OK for you because that's a subclass of Graphics.
It has to work that way because Graphics is abstract and fillArc in Graphics is abstract. Since you want to use that method they have to supply you with an instnace of a class in which fillArc is not abstract - ie Graphics2D.
Normally none of this matters, but here the OP is adamant that he doesn't want to use Graphics2D, which he cannot avoid by referring to Graphics instead.

Member Avatar for hfx642

Anyways... It just works, and I'm glad.
Back to the problem...
Using fillArc(), draw your completed "pie" (circle),
section by section (You're trying to animate your "pie" right?).
Put THIS into a loop. Vary the colour and the "starting degree" parameter.
This will get your "pie" to spin/rotate.

Well thanx very much i did as you said but for now I'm stuck in the rotating of my pie
Question how do I get my theta randomly....?
As u mentioned each time I will update my theta through the outer loop and and
Repaint it again right?

Please tell me - why did you specify "with out using Graphics2d class" in your original post? Just interested....

Member Avatar for hfx642

Well... Straight up is 90 degrees.
So, I would do

int theta = (90 + X) % 360;

inside your loop and always keep track of X.
You'll have to adjust the formula for (counter)clockwise rotation.
(Sorry, but... I don't have my code for this project at home.)
You could put the whole thing in a method and call it with a new X (instead of a loop) as your application is progressing (such as at start up).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.