KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  *
3  * StaticChartFill.java, rendering demo of jchart2d.
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 import info.monitorenter.gui.chart.Chart2D;
27 import info.monitorenter.gui.chart.ITrace2D;
28 import info.monitorenter.gui.chart.layout.ChartPanel;
29 import info.monitorenter.gui.chart.traces.Trace2DSimple;
30 import info.monitorenter.gui.chart.traces.painters.TracePainterFill;
31
32 import java.awt.Color JavaDoc;
33 import java.awt.event.WindowAdapter JavaDoc;
34 import java.awt.event.WindowEvent JavaDoc;
35 import java.util.Random JavaDoc;
36
37 import javax.swing.JFrame JavaDoc;
38
39 /**
40  * A demo chart that uses a
41  * {@link info.monitorenter.gui.chart.traces.painters.TracePainterFill}.
42  * <p>
43  *
44  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
45  *
46  * @version $Revision: 1.1 $
47  *
48  */

49 public final class StaticChartFill {
50
51   /**
52    * Main entry.
53    * <p>
54    *
55    * @param args
56    * ignored.
57    */

58   public static void main(final String JavaDoc[] args) {
59     // Create a chart:
60
Chart2D chart = new Chart2D();
61
62     // Create an ITrace:
63
ITrace2D trace = new Trace2DSimple();
64     trace.setTracePainter(new TracePainterFill(chart));
65     trace.setColor(Color.DARK_GRAY);
66     // Add all points, as it is static:
67
double count = 0;
68     double value;
69     double place = 0;
70     Random JavaDoc random = new Random JavaDoc();
71     for (int i = 120; i >= 0; i--) {
72       count += 1.0;
73       place += 1.0;
74       value = random.nextDouble() * 10.0 + i;
75       trace.addPoint(place, value);
76     }
77     // Add the trace to the chart:
78
chart.addTrace(trace);
79
80     // Make it visible:
81
// Create a frame.
82
JFrame JavaDoc frame = new JFrame JavaDoc("StaticChartFill");
83     // add the chart to the frame:
84
frame.getContentPane().add(new ChartPanel(chart));
85     frame.setSize(400, 300);
86     // Enable the termination button [cross on the upper right edge]:
87
frame.addWindowListener(new WindowAdapter JavaDoc() {
88       public void windowClosing(final WindowEvent JavaDoc e) {
89         System.exit(0);
90       }
91     });
92     frame.setVisible(true);
93   }
94
95   /**
96    * Defcon.
97    * <p>
98    */

99   private StaticChartFill() {
100     // nop
101
}
102 }
103
Popular Tags