/** The main function for displaying the Life game area. */ private void paintCanvas(Graphics g) { Dimension canvasSize = canvas.getSize(); int xdelta = canvasSize.width / modelSize; if (xdelta == 0) { xdelta = 1; } int ydelta = canvasSize.height / modelSize; if (ydelta == 0) { ydelta = 1; } for (int x = 0; x < modelSize; ++x) { for (int y = 0; y < modelSize; ++y) { int age = theModel.getCell(x, y); // System.out.print("("+x+","+y+"): " + age); if (generationCount >= 10 && age > 0) { age = 1 + 10 * age / generationCount; } if (age >= 10) { age = 9; } Color c = (age > 0) ? colorMap[age - 1] : Color.black; // System.out.println(" " + age + " color: " + c); g.setColor(c); g.fillRect(x * xdelta, y * ydelta, xdelta, ydelta); } } Thread.yield(); }