01: import java.awt.*;
02: import java.awt.event.*;
03: import JSci.awt.*;
04: import JSci.swing.*;
05:
06: /**
07: * Sample program demonstrating use of the Swing/AWT contour plot component.
08: * @author Mark Hale
09: * @version 1.0
10: */
11: public class ContourPlotDemo extends Frame {
12: public static void main(String arg[]) {
13: new ContourPlotDemo();
14: }
15:
16: public ContourPlotDemo() {
17: super ("JSci Contour Plot Demo");
18: addWindowListener(new WindowAdapter() {
19: public void windowClosing(WindowEvent evt) {
20: dispose();
21: System.exit(0);
22: }
23: });
24: setSize(250, 250);
25: add(new ContourPlot(createContourData()));
26: setVisible(true);
27: }
28:
29: private static double[][] createContourData() {
30: double data[][] = new double[50][50];
31: double x, y;
32: for (int i = 0; i < data.length; i++) {
33: for (int j = 0; j < data[0].length; j++) {
34: x = (i - data.length / 2.0) * 3.0 / data.length;
35: y = (j - data[0].length / 2.0) * 3.0 / data[0].length;
36: data[i][j] = Math.exp(-x * x - y * y);
37: }
38: }
39: return data;
40: }
41: }
|