import java.awt.*; class DrawSim extends java.awt.Canvas { //double-buffering private Image image2; private Graphics g2; private Dimension mySize; private int XSIZE,YSIZE,XOFFSET,YOFFSET; private int MAXPOINTS=1000; private double xscale,yscale,XMAX,XMIN,YMAX,YMIN; private int xpoints[]; private int ypoints[]; private int lastPoint; DrawSim(){ xpoints = new int[MAXPOINTS]; ypoints = new int[MAXPOINTS]; setBackground(Color.white); } public void paint(Graphics g){ // setup offscreen graphics object, setup axes and scale parameters // resize background size if necessary if (g2 == null) {determineSize();paintSetup();} else if ((this.size().width!=mySize.width) || (this.size().height!=mySize.height)) paintSetup(); // paint background g2.setColor(this.getBackground()); g2.fillRect(0,0,mySize.width,mySize.height); // graph axes etc myAxes(); // go through all points and paint g2.setColor(Color.blue); for(int i=0;i=0) && (ix==xpoints[lastPoint]))) { // wrap arrays around to avoid out-of-bounds problems if (++lastPoint>=MAXPOINTS) lastPoint=0; xpoints[lastPoint]=ix; ypoints[lastPoint]=iy; } repaint(); } private double myformat(double x, int n){ double d; int i; d=x*n; i=(int)d; d=(double)i/(double)n; return(d); } public void clearScreen(){ lastPoint=-1; } }