import java.applet.Applet; import java.awt.*; import java.lang.*; public class SimpleApplet extends Applet { int i, nPaint; int nPts = 200; double y[]; double x[]; double mx,my,bx,by; public void init(){ y=new double[nPts]; x=new double[nPts]; nPaint=0; for(i = 0;i < nPts; i++){ x[i]=1.*i*Math.PI/nPts; y[i]=Math.sin(x[i]); } world2win(0,1,Math.PI,0.0); } public void paint(Graphics g) { int x1,x2, y1,y2; nPaint++; x1=(int)(mx*x[0]+bx); y1=(int)(my*y[0]+by); for(i = 0;i < nPts; i++) { x2=(int)(mx*x[i]+bx); y2=(int)(my*y[i]+by); g.drawLine(x1,y1,x2,y2); x1=x2; y1=y2; } g.drawString("Number of paint calls:"+nPaint,80,75); } void world2win(double xl, double yt, double xr, double yb) { double lm=5., rm=295., tm=5., bm=95.; mx = (lm-rm) / (xl-xr); bx = (xl*rm-xr*lm) / (xl-xr); my = (tm-bm) / (yt-yb); by = (yb*tm-yt*bm) / (yb-yt); } }