-Buffer.java------------------------------------------------------------------ public class Buffer{ private int[][] cells; private int width, height; public Buffer(int y, int x){ width = x; height = y; cells = new int[y][x]; } public void clear(){ for(int y=0;y0) numLivingNeighbors++; if(cells[(height+y-1)%height][x]>0) numLivingNeighbors++; if(cells[(height+y-1)%height][(width+x+1)%width]>0) numLivingNeighbors++; if(cells[y][(width+x-1)%width]>0) numLivingNeighbors++; if(cells[y][(width+x+1)%width]>0) numLivingNeighbors++; if(cells[(height+y+1)%height][(width+x-1)%width]>0) numLivingNeighbors++; if(cells[(height+y+1)%height][x]>0) numLivingNeighbors++; if(cells[(height+y+1)%height][(width+x+1)%width]>0) numLivingNeighbors++; return numLivingNeighbors; } } -LifeCanvas.java---------------------------------------------------------------- import java.awt.*; import java.awt.event.*; public class LifeCanvas extends Canvas implements MouseListener, MouseMotionListener{ private Buffer front, back; private int width, height, size; boolean[][] changed; boolean auto; Image offscreen; Color[] colors; public LifeCanvas(int y, int x, int cellSize){ height = y; width = x; size = cellSize; changed = new boolean[y][x]; for(int i=0;y0){ if(front.getCell(y,x)<9){ back.setCell(y,x,front.getCell(y,x)+1); }else{ back.setCell(y,x,9); } }else{ back.setCell(y,x,0); } } if(numNeighbors==3){ if(front.getCell(y,x)>0){ if(front.getCell(y,x)<9){ back.setCell(y,x,front.getCell(y,x)+1); }else{ back.setCell(y,x,9); } }else{ back.setCell(y,x,1); } } if(numNeighbors>3) back.setCell(y,x,0); } } swapBuffers(); repaint(); } private void swapBuffers(){ Buffer temp = front; front = back; back = temp; } public void update(Graphics g){ paint(g); } public void invalidate() { super.invalidate(); offscreen = null; } public void paint(Graphics g){ if(offscreen == null) { offscreen = createImage(getSize().width, getSize().height); } Graphics og = offscreen.getGraphics(); og.setClip(0,0,getSize().width, getSize().height); for(int y=0;y0){ front.setCell(y,x,0); }else{ front.setCell(y,x,1); } changed[y][x]=true; repaint(); } } } public void mouseDragged(MouseEvent event){ Point location = event.getPoint(); if(location.getX()0){ front.setCell(y,x,0); }else{ front.setCell(y,x,1); } changed[y][x]=true; repaint(); } } } public void mouseReleased(MouseEvent arg0){ for(int y=0;y