// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.*;
import java.awt.event.*;
import java.util.*;

import javax.swing.*;

public class DynNum extends JFrame implements ActionListener {
   private JTextArea txt;
   private JButton btn;
   public DynNum() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      getContentPane().setLayout(new GridLayout(2, 1));
      txt = new JTextArea();
      getContentPane().add(txt);
      btn = new JButton("Start");
      btn.addActionListener(this);
      getContentPane().add(btn);
      pack();
   }
   public void addNum(int n) {
      txt.setText(txt.getText() + " " + n + "\r\n");
      pack();
   }
   public void actionPerformed(ActionEvent ev) {
      if (ev.getSource() == btn) {
         T t = new T(this);
         t.start();
      }
   }
   public static void main(String[] args) {
      DynNum f = new DynNum();
      f.show();
   }
}

class T extends Thread {
   private DynNum dn;
   public T(DynNum dn) {
      this.dn = dn;
   }
   public void run() {
      Random rng = new Random();
      for(int i = 0; i < 10; i++) {
         dn.addNum(rng.nextInt(100));
         try {
            Thread.sleep(1000);
         } catch (InterruptedException e) {
         }
      }
   }
}
