Write a program that accepts one command line argument, the name of a file containing data to be drawn as a pie chart, and draws the pie chart in a window.
• Sample data file, birds.txt, contains the one-word categories of birds, and the number of each kind.
swallow 10
magpie 5
fairywren 7
osprey 2
fantail 3
• The pie chart must use a different colour for each pie segment, and display a legend that shows the labels and the percentage for each.
• Your program should support up to 10 categories.
[Added from comment]
This is what I have so far...
import javax.swing.*;
import java.awt.*;
public class Pie4 {
public static void main(String[] args) {
JFrame f = new JFrame("Pie chart");
f.setSize(600, 350);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new PieChart());
f.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.*;
public class PieChart
extends JComponent {
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
Graphics2D g3 = (Graphics2D) g.create();
g3.setColor(Color.BLACK);
g2.setColor(Color.BLUE);
g2.fillArc(50, 50, 150, 150, 0, 360);
}
}
I can't figure out the rest