KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > demos > MinimalDynamicChart


1 /*
2  * MinimalDynamicChart.java of project jchart2d, a demonstration
3  * of the minimal code to set up a chart with dynamic data.
4  * Copyright (C) Achim Westermann, created on 10.12.2004, 13:48:55
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * If you modify or optimize the code in a useful way please let me know.
21  * Achim.Westermann@gmx.de
22  *
23  */

24 package info.monitorenter.gui.chart.demos;
25
26
27 import info.monitorenter.gui.chart.Chart2D;
28 import info.monitorenter.gui.chart.ITrace2D;
29 import info.monitorenter.gui.chart.io.ADataCollector;
30 import info.monitorenter.gui.chart.io.RandomDataCollectorOffset;
31 import info.monitorenter.gui.chart.traces.Trace2DLtd;
32
33 import java.awt.Color JavaDoc;
34 import java.awt.event.WindowAdapter JavaDoc;
35 import java.awt.event.WindowEvent JavaDoc;
36
37 import javax.swing.JFrame JavaDoc;
38
39 /**
40  * Demonstrates minimal effort to create a dynamic chart.
41  * <p>
42  *
43  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
44  *
45  */

46 public final class MinimalDynamicChart {
47
48   /**
49    * Main entry.
50    * <p>
51    *
52    * @param args
53    * ignored
54    */

55   public static void main(final String JavaDoc[] args) {
56     // Create a chart:
57
Chart2D chart = new Chart2D();
58     // Create an ITrace:
59
// Note that dynamic charts need limited amount of values!!!
60
ITrace2D trace = new Trace2DLtd(800);
61     trace.setColor(Color.RED);
62
63     // Add the trace to the chart:
64
chart.addTrace(trace);
65
66     // Make it visible:
67
// Create a frame.
68
JFrame JavaDoc frame = new JFrame JavaDoc("MinimalDynamicChart");
69     // add the chart to the frame:
70
frame.getContentPane().add(chart);
71     frame.setSize(400, 300);
72     // Enable the termination button [cross on the upper right edge]:
73
frame.addWindowListener(new WindowAdapter JavaDoc() {
74       public void windowClosing(final WindowEvent JavaDoc e) {
75         System.exit(0);
76       }
77     });
78     frame.setVisible(true);
79     // Every 50 milliseconds a new value is collected.
80
ADataCollector collector = new RandomDataCollectorOffset(trace, 2);
81     collector.start();
82   }
83
84   /** Defcon. */
85   private MinimalDynamicChart() {
86     // nop
87
}
88 }
89
Popular Tags