 // 初期値の場所を乱数にしたセルオートマトン [Auto2.java](JDK 1.0.2)
  import java.applet.Applet;
  import java.awt.*;
 //! import java.awt.event.*;  // JDK 1.1
 //! public class Auto2 extends Applet
 //!        implements ActionListener,ItemListener { // JDK 1.1
  public class Auto2 extends Applet { //!
     int n=1;                        // 乱数の数
     Choice nChoice;                 // チョイス
     Button button_s;                // STARTボタン
  public void init() {               // ロード時の初期化メソッド
     button_s=new Button("START");   // STARTボタン
     nChoice = new Choice();         // チョイス
     for (int i=1; i<=10; i++) {     // チョイスの設定
        nChoice.addItem(""+i);
     }
     add(button_s);
     add(nChoice);                      // チョイス
     add(new Label("Number"));          // ラベル
  //!   button_s.addActionListener(this);  // JDK 1.1
  //!   nChoice.addItemListener(this);     // JDK 1.1
  } //end init
  //!//============= JDK 1.1 イベント処理(ボタン) =============
  //!public void actionPerformed(ActionEvent e) { // イベント処理
  //!   if (e.getSource() == button_s) {          // JDK 1.1
  //!      repaint();
  //!   } //end if
  //!} //end actionPerformed
  //!//============ JDK 1.1 イベント処理(チョイス) ============
  //!public void itemStateChanged(ItemEvent e) { // JDK 1.1 
  //!   if (e.getSource() == nChoice) {          // チョイス
  //!      n=nChoice.getSelectedIndex()+1;       // nの取出し
  //!   } //end if
  //!} //end itemStateChanged
  //============= JDK 1.0.2 イベント処理 ======================
  public boolean action(Event e, Object o) {  //! イベントの処理
     String label = o.toString();             //!
     if (e.target instanceof Button) {        //! STARTボタン
        if (label.equals("START")) { repaint(); } //!
     } else if (e.target instanceof Choice) { //! チョイスの変更 
        n=nChoice.getSelectedIndex()+1;       //! nの取出し
     }            //!
     return true; //!
  } //end action  //!
  //================= グラフィックスの表示 =================
  public void paint( Graphics g ) {
     int x[], y[];                           // 配列
     int w,h,button_h,r;
  //!   w=getSize().width;                   // 横の大きさ
  //!   h=getSize().height;                  // 縦の大きさ
     w=size().width;                         //!横の大きさ
     h=size().height;                        //!縦の大きさ
     x=new int[w];                           // 配列の生成
     y=new int[w];                           // 配列の生成
     for (int i=1; i<=n; i++) {
        while (true) {
           r=(int)(Math.random()*w);        // 乱数の発生
           if (x[r] ==0) { // 既に設定されているかチェック
              x[r]=1;      // 初期値の位置を乱数で指定する
              break;
           }
        } //end while
     } //end for
     g.setColor(Color.blue);                 // 色の設定
     for (int j=0; j<h-40; j++) {            // 縦のループ
       for (int i=1; i<w-1; i++) {           // 横のループ
          y[i]=(x[i-1]+x[i+1])%2;
          if (y[i] == 1) {
             g.drawLine(i,j+40,i,j+40);      // 点の描画
          }
       }
       System.arraycopy(y,0,x,0,w);          // 配列の複写
     }
  } //end paint
 } //end Auto2
