import java.awt.*; import java.awt.Canvas; import java.util.*; import java.awt.image.*; import java.awt.event.*; public class nCanvas extends Canvas { Image buffImage; Graphics gBuff; boolean pixels[][]; double rx0=0.0, ry0=0.0, rx1=1.0, ry1=1.0; // real coord of left-bottom point and right-top point double rwidth=1.0, rheight=1.0; // width and hwight in real public void makeBuffer(){ Dimension ps=getSize(); buffImage=createImage(ps.width,ps.height); if(buffImage==null){ System.out.println("Could not make buffer.");} gBuff=buffImage.getGraphics(); pixels= new boolean[ps.width][ps.height]; } public void paint(Graphics g){ g.drawImage(buffImage,0,0,this); } public void update(Graphics g){ paint(g); } //set screen size in real coordinate public void screen(double x0, double y0, double x1, double y1){ double tmp; if(x0>x1){ tmp=x0; x0=x1; x1=tmp;}; if(y0>y1){ tmp=y0; y0=y1; y1=tmp;}; rx0=x0; ry0=y0; rx1=x1; ry1=y1; rwidth=rx1-rx0; rheight=ry1-ry0; } //clear screen public void eraseBuff(){ Dimension ps=getSize(); Color tmpcol; // gBuff.clearRect(0,0,ps.width,ps.height); tmpcol=gBuff.getColor(); gBuff.setColor(Color.white); gBuff.fillRect(0,0,ps.width,ps.height); update(this.getGraphics()); for(int xi=0; xi