KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ContourPlotDemo


1 import java.awt.*;
2 import java.awt.event.*;
3 import JSci.awt.*;
4 import JSci.swing.*;
5
6 /**
7 * Sample program demonstrating use of the Swing/AWT contour plot component.
8 * @author Mark Hale
9 * @version 1.0
10 */

11 public class ContourPlotDemo extends Frame {
12         public static void main(String JavaDoc arg[]) {
13                 new ContourPlotDemo();
14         }
15         public ContourPlotDemo() {
16                 super("JSci Contour Plot Demo");
17                 addWindowListener(new WindowAdapter() {
18                         public void windowClosing(WindowEvent evt) {
19                                 dispose();
20                                 System.exit(0);
21                         }
22                 });
23                 setSize(250,250);
24                 add(new ContourPlot(createContourData()));
25                 setVisible(true);
26         }
27         private static double[][] createContourData() {
28                 double data[][]=new double[50][50];
29                 double x,y;
30                 for(int i=0;i<data.length;i++) {
31                         for(int j=0;j<data[0].length;j++) {
32                                 x=(i-data.length/2.0)*3.0/data.length;
33                                 y=(j-data[0].length/2.0)*3.0/data[0].length;
34                                 data[i][j]=Math.exp(-x*x-y*y);
35                         }
36                 }
37                 return data;
38         }
39 }
40
41
Popular Tags