//Mike Piff, CICS, University of Sheffield (1997) import java.awt.*; public class Graph extends Canvas{ private RungeKutta rk=null; private String independentvariable,dependentvariable; public Graph(RungeKutta rk,String xstr,String ystr){ this.rk=rk; independentvariable=xstr; dependentvariable=ystr; } public void drawAxes(){ Graphics g=getGraphics(); rk.drawAxes(g); g.dispose(); } public void paint(Graphics g){ rk.reStart(); } public boolean mouseMove(Event e,int x,int y){ if (e.target!=this) return false; int lowx=x-rk.graphBorder; int lowy=y-rk.graphBorder; if ((rk.graphDim!=null)&& ((lowx>=0)&&(lowx<=rk.graphDim.width-2*rk.graphBorder)&& (lowy>=0)&&(lowy<=rk.graphDim.height-2*rk.graphBorder))){ rk.showStatus(independentvariable+"="+rk.graphX(lowx)+", "+dependentvariable+"="+rk.graphY(lowy)); return true; } rk.showStatus(""); return false; } private int x,y; public boolean mouseDown(Event e,int x,int y){ if (e.target!=this) return false; this.x=x; this.y=y; int lowx=x-rk.graphBorder; int lowy=y-rk.graphBorder; if ((rk.graphDim!=null)&& ((lowx>=0)&&(lowx<=rk.graphDim.width-2*rk.graphBorder)&& (lowy>=0)&&(lowy<=rk.graphDim.height-2*rk.graphBorder))){ rk.initPoint.x=rk.graphX(lowx); rk.initPoint.y=rk.graphY(lowy); rk.textInitX.setText(rk.curtail(String.valueOf(rk.initPoint.x))); rk.textInitY.setText(rk.curtail(String.valueOf(rk.initPoint.y))); rk.checkScroll(); rk.drawGraph(); return true; } return false; } public boolean mouseDrag(Event e,int x,int y){ if (rk.order<2) return false; if (e.target!=this) return false; if (Math.abs(x-this.x)<10) return false; double dydx=((double)(this.y-y))/(x-this.x); rk.initPoint.z=dydx; rk.textInitdydx.setText(rk.curtail(String.valueOf(dydx))); repaint(); return true; } }