// An Unresposive Counting Applet - by Derek Molloy

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class BadCounter extends Applet implements ActionListener
{
	private int count = 0;
	private Button start, stop;
	private TextField countField;
	private boolean running = true;

	public void init() 
	{
	  countField = new TextField(10);
	  stop = new Button("Stop");
	  start = new Button("Start");
	  this.add(countField);
	  start.addActionListener(this);
	  this.add(start);
	  stop.addActionListener(this);
	  this.add(stop);
	}

	public void go() 
	{
	  while (running) 
	  {
	    try 
	    { 
	      Thread.currentThread().sleep(100); 
	    } 
	    catch (InterruptedException e)
	    {  }  //do nothing
	    countField.setText(Integer.toString(count++));
	  }
	}
	
	public void actionPerformed(ActionEvent e) 
	{ 
	  if (e.getSource().equals(start))
	  {
	    this.go();	
	  }
	  else if (e.getSource().equals(stop))
	  {
	    this.running = !this.running;
	  }
	}
} 
