public class PieChart
extends java.lang.Object
Wedge
objects, each of
which specifies its own label and width (in percent), plus an overall title
for the pie chart.
Note that this class should probably ensure that the total percentages of all its wedges adds up to 100% (within some margin of error).
Modifier and Type | Class and Description |
---|---|
private class |
PieChart.PieChartPanel
This inner class provides the panel on which the arcs of the pie wedges
and their labels will be drawn.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
title
The title for the overall pie chart.
|
private java.util.List<Wedge> |
wedges
The list of wedges, each of which specifies its own label and its own
width (in percent).
|
private java.util.List<Wedge> wedges
private java.lang.String title
Note that we wouldn't really need a field to hold this info, since it is
passed in as a parameter to the constructor and only used within the
constructor. However, as a title is conceptually an element of a pie
chart, it makes conceptual sense to have this field. Moreover, as we
might later want to modify this class to allow for modification of the
title of an existing pie chart (e.g., adding
setTitle(String title)
as a mutator) or we might later want
to add the title to the text within the chart itself, the design choice
was to make this a field so that these additions do not require later
modifications of existing data structures.
public PieChart(java.lang.String title, java.util.List<Wedge> wedges)
JFrame
as
the heavy-weight container for the graphics objects.
Note that because this is our first exercise in this course on
constructing graphics, we don't need to have it do anything fancy, like
automatically resize its contents if the window is resized. However, we
will organize the class by having the actual chart itself be drawn in an
object that is an instance of a subclass of JPanel
. This
will allow for easier additions to this class that may come later.
title
- The title of the chart itself.wedges
- The list of wedges that will comprise the pie.