// plot_saddle.java plot saddleola ortho with height colors import java.io.*; import java.*; import java.awt.*; import java.awt.event.*; public class plot_saddle extends Frame { // mouse and display variables int xm, ym, bm; // mouse position int height = 700; int width = 700; double xmin = -1.0; // typically determined from data double xmax = 1.0; double ymin = -1.0; double ymax = 1.0; double zmin = -1.0; double zmax = 1.0; double tmin = -0.5; double tmax = 0.5; double t = tmin; int nx = 20; int ny = 20; int nz = 20; int nt = 20; double hx = (xmax-xmin)/nx; double hy = (ymax-ymin)/ny; double hz = (zmax-zmin)/nz; double ht = (tmax-tmin)/nt; double ya = 0.5; // orthographic typ 0.1 to 0.5 double xs = (0.666*(width-100))/(xmax-xmin); double ys = (0.666*(height-100))/(ymax-ymin); int xp, yp; // computed by saddle public plot_saddle() { System.out.println("plot_saddle.java running"); setTitle("plot_saddle"); setSize(width,height); setBackground(Color.white); setForeground(Color.black); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setVisible(true); this.addMouseListener (new mousePressHandler()); do_plot(); } // plot_saddle constructor void do_plot() { // set up here // plot repaint(); // wait for mouse events } // end do_program class mousePressHandler extends MouseAdapter { public void mousePressed (MouseEvent e) { xm = e.getX(); ym = e.getY(); bm = e.getButton(); // System.out.println("down xm="+xm+", ym="+ym+", bm="+bm); // debug if(in_rect(width-70, height-20, 30, 20)) { // do something, run requestFocus(); MyThread do_run = new MyThread(); // allocate do_run thread do_run.start(); // terminates } else if(in_rect(width-105, height-20, 30, 20)) { // do something, next t = t + ht; requestFocus(); repaint(); } else if(in_rect(width-145, height-20, 35, 20)) { // do something, back t = t - ht; requestFocus(); repaint(); } if(in_rect(width-35, height-20, 30, 20)) System.exit(0); } // end mousePressed } // end mousePressHandler boolean in_rect(int x, int y, int w, int h) { return xm>x && xmy && ym9) {g.setColor(Color.gray); return; } switch(i) { case 0: g.setColor(Color.black); break; case 1: g.setColor(Color.pink); break; // should be brown case 2: g.setColor(Color.red); break; case 3: g.setColor(Color.orange); break; case 4: g.setColor(Color.yellow); break; case 5: g.setColor(Color.green); break; case 6: g.setColor(Color.blue); break; case 7: g.setColor(Color.magenta); break; case 8: g.setColor(Color.cyan); break; case 9: g.setColor(Color.gray); break; } } // end set_color class MyThread extends Thread { MyThread() { } // end MyThread constructor public void run() { t = tmin; try { for(int i=0; i