O'Reilly logo

Sams Teach Yourself Java™ in 24 Hours, Sixth Edition by Rogers Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Baking a Pie Graph

To draw this hour to a close, you create PiePanel, a GUI component that displays a pie graph. This component is a subclass of JPanel, a simple Swing container that’s useful as a place to draw something.

One way to begin creating a class is to define the way objects of the class are created. Programs that use the PiePanel class must undertake the following steps:

• Create a PiePanel object by using the constructor method PiePanel(int). The integer specified as an argument is the number of slices the pie graph contains.

• Call the object’s addSlice(Color, float) method to give a slice the designated color and value.

The value of each slice in PiePanel is the quantity represented by that slice.

For example, Table 23.1 displays ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required