Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.geom.*;
- import javax.swing.*;
- import java.util.*;
- public class PieGraph2 extends JFrame {
- public PieGraph2(){
- super("Pie Graph");
- setSize(700, 600);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- PiePane p = new PiePane();
- p.addSlice(60F, Color.yellow);
- p.addSlice(100F, Color.magenta);
- p.addSlice(100F, Color.cyan);
- p.addSlice(80F, Color.red);
- p.addSlice(20F, Color.blue);
- add(p);
- setVisible(true);
- }
- public static void main(String[] arguments){
- PieGraph2 eric = new PieGraph2();
- }
- }
- class PiePane extends JPanel {
- ArrayList<Color> colors;
- ArrayList<Float> angles;
- public PiePane(){
- colors = new ArrayList<>();
- angles = new ArrayList<>();
- }
- public void addSlice(float degrees, Color color){
- colors.add(color);
- angles.add(degrees);
- }
- public void paintComponent(Graphics comp){
- Graphics2D comp2D = (Graphics2D)comp;
- int count = 0;
- for(int i = 0; i < angles.size(); i++){
- comp2D.setColor(colors.get(i));
- System.out.println("count: " + count + ", new count: " + (count + angles.get(i)));
- comp2D.fill(new Arc2D.Float(200F, 200F, 300F, 300F, count, angles.get(i), Arc2D.PIE));
- count += angles.get(i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement