• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HOW to draw an ARC on a Frame / Panel

 
Vaibhav Manwatkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
I want to draw a pie chart in which I am using fillArc() to draw the PIE chart. but I have to use Frame or Panel for it, I can't Use Applets because the values using which I will draw the arc are in DataBase and Applets can't access databases. So what to do if I want to draw an arc on Frame or Panel...

Its urgent... please reply if you know...
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mention Frame and Panel which are AWT components so I assume you want to work in the AWT vis–a–vis Swing. Some suggestions:
1 — create a class that extends either Canvas or Panel and override its paint method to do your drawing

2 — import the java.awt.geom package which gives access to the Arc2D class. You will need the Graphics2D context (g2) to draw/fill your arcs.

3 — consider basing all drawing calculations relative to the center of the drawing surface. Math.atan2(y1 - y2, x1 - x2) is a convenient way to get the angle of rotation for any pie slice.

4 — it takes a little experimenting to figure out how to use Arc2D; the Arc2D api is a starting point. The java2D tutorial has an example on the Stroking and Filling Graphics Primitives page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic