//ContourPlot1.java draw a contour plot // data input nx ny first line // x y z many lines smallest x first // followed by smallest y to largest import java.awt.*; import java.awt.event.*; import java.io.*; import java.*; public class ContourPlot1 extends Frame { int ncont = 9; // contour lines zz normalized double dzz = 1.0/(ncont+1); // first is dzz Color cont_color[] = {Color.black, Color.gray, Color.magenta, Color.cyan, Color.blue, Color.green, Color.yellow, Color.orange, Color.red}; int width=800, height=800; double xp[] = new double[4]; // reused double yp[] = new double[4]; double xx[]; // data as read double yy[]; double zz[]; double xxf[]; // refined grid double yyf[]; double zzf[]; int n_input; double xmin, xmax, ymin, ymax, zmin, zmax; int nxx=0, nyy=0, nxy=0; // index i*nxx+j int n=0; boolean connect; boolean debug = true; boolean refine = true; // four times as many points ContourPlot1() { setTitle("ContourPlot1"); try{ read_data(); if(refine) refine_grid(); } catch(IOException exception) { } setSize(width,height); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); n=0; connect=false; this.addMouseListener (new mousePressHandler()); repaint(); } // end ContourPlot1 class mousePressHandler extends MouseAdapter { public void mousePressed (MouseEvent e) { int x, y, z, b; x = e.getX(); y = e.getY(); b = e.getButton(); if(b==3 && n>0) { connect=true; } requestFocus(); System.out.println("at x="+x+" y="+y+" b="+b); // debug print repaint(); } } // end mousePressHandler int scalex(double a) { return (int)((double)(width-20)*a)+10; } // end scalex int scaley(double a) { return (int)((double)(height-60)*(a))+50; } // end scaley public void paint(Graphics g) { double x1, y1, x2, y2, z11, z12, z21, z22; double z, nearz; boolean pt1, pt2; String fstring; g.setColor(Color.black); for(int i=0; i6) // exit on blank or short line { if(debug && n_input==0) System.out.println("input: "+input_line); len = input_line.length(); index = 0; // first x if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index+1); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index,last)); if(debug && n_input==0) System.out.println("amount="+amount); xx[n_input] = amount; index = last+1; // second y if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(debug && n_input==0) System.out.println("last="+last); amount = Double.parseDouble(input_line.substring(index,last)); if(debug && n_input==0) System.out.println("amount="+amount); yy[n_input] = amount; index = last+1; // third z if(debug && n_input==0) System.out.println("index="+index); last = input_line.indexOf(' ',index); if(last