Advertisement
horselurrver

PieGraph

Nov 26th, 2016
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.geom.*;
  3. import javax.swing.*;
  4. import java.util.*;
  5.  
  6. public class PieGraph2 extends JFrame {
  7. public PieGraph2(){
  8. super("Pie Graph");
  9. setSize(700, 600);
  10. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  11. PiePane p = new PiePane();
  12. p.addSlice(60F, Color.yellow);
  13. p.addSlice(100F, Color.magenta);
  14. p.addSlice(100F, Color.cyan);
  15. p.addSlice(80F, Color.red);
  16. p.addSlice(20F, Color.blue);
  17. add(p);
  18. setVisible(true);
  19. }
  20.  
  21. public static void main(String[] arguments){
  22. PieGraph2 eric = new PieGraph2();
  23. }
  24. }
  25.  
  26. class PiePane extends JPanel {
  27. ArrayList<Color> colors;
  28. ArrayList<Float> angles;
  29. public PiePane(){
  30. colors = new ArrayList<>();
  31. angles = new ArrayList<>();
  32. }
  33. public void addSlice(float degrees, Color color){
  34. colors.add(color);
  35. angles.add(degrees);
  36. }
  37. public void paintComponent(Graphics comp){
  38. Graphics2D comp2D = (Graphics2D)comp;
  39. int count = 0;
  40. for(int i = 0; i < angles.size(); i++){
  41. comp2D.setColor(colors.get(i));
  42. System.out.println("count: " + count + ", new count: " + (count + angles.get(i)));
  43. comp2D.fill(new Arc2D.Float(200F, 200F, 300F, 300F, count, angles.get(i), Arc2D.PIE));
  44. count += angles.get(i);
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement