• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HOW to draw an ARC on a Frame / Panel

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic