Version 5

This is a trivial change. I pulled out some comments, and added calls to the Canvas method getSize. This might not work for you.

If you get a gray area where the Life board should be (instead of blue and white ovals), your browser probably doesn't understand getSize. You need a more modern browser, or you need to view this applet using appletviewer.

To see why this is a cool thing to do, run the applet using appletviewer, and change the size of the applet window. Everything is automatically resized to fit.

Top     Version 4     Version 6    

Source code:

import java.awt.*;
import java.applet.Applet;

public class Life extends Applet
{
  int boardSize = 10;
  boolean[][] board = new boolean[boardSize][boardSize];
  Button stepButton;
  MyCanvas canvas;

  public void init ()
  {
    setLayout (new BorderLayout ());

    stepButton = new Button ("Step");
    add (BorderLayout.NORTH, stepButton);

    canvas = new MyCanvas (board, boardSize);
    add (BorderLayout.CENTER, canvas);

    for (int i = 0; i