KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > demo > Pie3DChartDemo2


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * --------------------
23  * Pie3DChartDemo2.java
24  * --------------------
25  * (C) Copyright 2002, 2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: Pie3DChartDemo2.java,v 1.5 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 18-Oct-2002 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.demo;
39
40 import java.awt.Color JavaDoc;
41 import java.awt.event.ActionEvent JavaDoc;
42 import java.awt.event.ActionListener JavaDoc;
43
44 import javax.swing.Timer JavaDoc;
45
46 import org.jfree.chart.ChartFactory;
47 import org.jfree.chart.ChartPanel;
48 import org.jfree.chart.JFreeChart;
49 import org.jfree.chart.plot.Pie3DPlot;
50 import org.jfree.data.DefaultPieDataset;
51 import org.jfree.ui.ApplicationFrame;
52 import org.jfree.ui.RefineryUtilities;
53 import org.jfree.util.Rotation;
54
55 /**
56  * A rotating 3D pie chart.
57  *
58  * @author David Gilbert
59  */

60 public class Pie3DChartDemo2 extends ApplicationFrame {
61
62     /**
63      * Creates a new demo.
64      *
65      * @param title the frame title.
66      */

67     public Pie3DChartDemo2(String JavaDoc title) {
68
69         super(title);
70
71         // create a dataset...
72
DefaultPieDataset data = new DefaultPieDataset();
73         data.setValue("Java", new Double JavaDoc(43.2));
74         data.setValue("Visual Basic", new Double JavaDoc(10.0));
75         data.setValue("C/C++", new Double JavaDoc(17.5));
76         data.setValue("PHP", new Double JavaDoc(32.5));
77         data.setValue("Perl", new Double JavaDoc(12.5));
78
79         // create the chart...
80
JFreeChart chart = ChartFactory.createPie3DChart("Pie Chart 3D Demo 2", // chart title
81
data, // data
82
true, // include legend
83
true,
84                                                          false
85                                                          );
86
87         chart.setBackgroundPaint(Color.yellow);
88         Pie3DPlot plot = (Pie3DPlot) chart.getPlot();
89         plot.setStartAngle(270);
90         plot.setDirection(Rotation.ANTICLOCKWISE);
91         plot.setForegroundAlpha(0.60f);
92         plot.setInteriorGap(0.33);
93         // add the chart to a panel...
94
ChartPanel chartPanel = new ChartPanel(chart);
95         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
96         setContentPane(chartPanel);
97
98         Rotator rotator = new Rotator(plot);
99         rotator.start();
100
101     }
102
103     /**
104      * Starting point for the demonstration application.
105      *
106      * @param args ignored.
107      */

108     public static void main(String JavaDoc[] args) {
109
110         Pie3DChartDemo2 demo = new Pie3DChartDemo2("Pie Chart 3D Demo 2");
111         demo.pack();
112         RefineryUtilities.centerFrameOnScreen(demo);
113         demo.setVisible(true);
114
115     }
116
117 }
118
119     // ****************************************************************************
120
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
121
// * Please note that commercial support and documentation is available from: *
122
// * *
123
// * http://www.object-refinery.com/jfreechart/support.html *
124
// * *
125
// * This is not only a great service for developers, but is a VERY IMPORTANT *
126
// * source of funding for the JFreeChart project. Please support us so that *
127
// * we can continue developing free software. *
128
// ****************************************************************************
129

130 /**
131  * The rotator.
132  *
133  * @author David Gilbert
134  */

135 class Rotator extends Timer JavaDoc implements ActionListener JavaDoc {
136
137     /** The plot. */
138     private Pie3DPlot plot;
139
140     /** The angle. */
141     private int angle = 270;
142
143     /**
144      * Constructor.
145      *
146      * @param plot the plot.
147      */

148     Rotator(Pie3DPlot plot) {
149         super(100, null);
150         this.plot = plot;
151         addActionListener(this);
152     }
153
154     /**
155      * Modifies the starting angle.
156      *
157      * @param event the action event.
158      */

159     public void actionPerformed(ActionEvent JavaDoc event) {
160         this.plot.setStartAngle(angle);
161         this.angle = this.angle + 1;
162         if (this.angle == 360) {
163             this.angle = 0;
164         }
165     }
166
167 }
168
Popular Tags