KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ChartTiming2.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: ChartTiming2.java,v 1.7 2003/06/30 12:14:34 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 29-Oct-2002 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.demo;
39
40 import java.awt.Graphics2D JavaDoc;
41 import java.awt.event.ActionEvent JavaDoc;
42 import java.awt.event.ActionListener JavaDoc;
43 import java.awt.geom.Rectangle2D JavaDoc;
44 import java.awt.image.BufferedImage JavaDoc;
45
46 import javax.swing.Timer JavaDoc;
47
48 import org.jfree.chart.ChartFactory;
49 import org.jfree.chart.JFreeChart;
50 import org.jfree.chart.plot.PlotOrientation;
51 import org.jfree.chart.plot.XYPlot;
52 import org.jfree.chart.renderer.XYDotRenderer;
53 import org.jfree.data.XYDataset;
54
55 /**
56  * Draws a scatter plot over and over for 10 seconds. Reports on how many redraws were achieved.
57  * <p>
58  * On my PC (SuSE Linux 8.2, JDK 1.4, 256mb RAM, 2.66ghz Pentium) I get 14 charts per second.
59  *
60  * @author David Gilbert
61  */

62 public class ChartTiming2 implements ActionListener JavaDoc {
63
64     /** A flag that indicates when time is up. */
65     private boolean finished;
66
67     /**
68      * Creates a new application.
69      */

70     public ChartTiming2() {
71     }
72
73     /**
74      * Runs the test.
75      */

76     public void run() {
77
78         this.finished = false;
79
80         // create a dataset...
81
XYDataset data = new SampleXYDataset2(1, 1440);
82
83         // create a scatter chart...
84
boolean withLegend = true;
85         JFreeChart chart = ChartFactory.createScatterPlot(
86             "Scatter plot timing", "X", "Y",
87             data,
88             PlotOrientation.VERTICAL,
89             withLegend, false, false
90         );
91
92         XYPlot plot = chart.getXYPlot();
93         plot.setRenderer(new XYDotRenderer());
94
95         BufferedImage JavaDoc image = new BufferedImage JavaDoc(400, 300, BufferedImage.TYPE_INT_RGB);
96         Graphics2D JavaDoc g2 = image.createGraphics();
97         Rectangle2D JavaDoc chartArea = new Rectangle2D.Double JavaDoc(0, 0, 400, 300);
98
99         // set up the timer...
100
Timer JavaDoc timer = new Timer JavaDoc(10000, this);
101         timer.setRepeats(false);
102         int count = 0;
103         timer.start();
104         while (!finished) {
105             chart.draw(g2, chartArea, null);
106             System.out.println("Charts drawn..." + count);
107             if (!finished) {
108                 count++;
109             }
110         }
111         System.out.println("DONE");
112
113     }
114
115     /**
116      * Receives notification of action events (in this case, from the Timer).
117      *
118      * @param event the event.
119      */

120     public void actionPerformed(ActionEvent JavaDoc event) {
121         this.finished = true;
122     }
123
124     /**
125      * Starting point for the application.
126      *
127      * @param args ignored.
128      */

129     public static void main(String JavaDoc[] args) {
130
131         ChartTiming2 app = new ChartTiming2();
132         app.run();
133
134     }
135
136 }
137
Popular Tags