ptg7068951
334 HOUR 23:Creating Java2D Graphics
TABLE 23.1 U.S. Student Loan Repayments
Amount repaid by students $101 billion
Amount loaned to students still in school $68 billion
Amount loaned to students making payments $91 billion
Amount loaned to students who defaulted $25 billion
You could use PiePanelto represent this data in a pie graph with the fol-
lowing statements:
PiePanel loans = new PiePanel(4);
loans.addSlice(Color.green, 101F);
loans.addSlice(Color.yellow, 68F);
loans.addSlice(Color.blue, 91F);
loans.addSlice(Color.red, 25F);
Figure 23.2 shows the result in an application frame that contains one com-
ponent: a PiePanelcreated with the student loan data.
Repaid
Loaned to Repayers
Loaned to
Students Loaned to Defaulters
FIGURE 23.2
Displaying student loan data on a
pie graph.
When a PiePanelobject is created, the number of slices is specified in the
constructor. You need to know three more things to be able to draw each
slice:
. The color of the slice, represented by a Colorobject
. The value represented by each slice
. The total value represented by all slices