Garbage.java




public class Garbage extends JApplet {
  JTextArea  Xout  = new JTextArea(10, 50);
  boolean f = false;
  int created = 0;

  public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(new JLabel("Garbage!"));
    cp.add(new JScrollPane(Xout));
    // As long as the flag hasn't been set, make Chairs:
    while(!f) {
      new Chair();
    }

    Xout.append(
      "\n Total Chairs created = " + created );

 }

 class Chair {

  int i;
  Chair() {
    i = ++created;
  }
  public void finalize() {
    f = true;
 }
}
public static void main(String[] args) {
        Console.run(new Garbage(), 600, 250);
}

} ///:~