/*De Threadklasse Second
3 attributen:
seconden (int)
tekstvak
object van de klasse TickTock (=gemeenschappelijk object)
constructor

methode run():
1 seconde slapen
als seconden = 60 -> Thread minute activeren; seconden = 0
anders seconden + 1
nieuwe waarde tonen in tekstvak
*/

import javax.swing.*;

public class Second extends Thread
{

	private int seconden;
	private JTextField tekstvak;
	private TickTock tik;

	public Second()
	{
		seconden = 0;
		tekstvak = new JTextField(15);
		tik = new TickTock();
	}

	public Second(JTextField a, TickTock b)
	{
		seconden = 0;
		tekstvak = a;
		tik = b;
	}

	public void run()
	{
		while(true)
		{
			try
			{
				this.sleep(1000);
			}
			catch(InterruptedException e)
			{
				e.printStackTrace();
			}
			if(seconden == 60)
			{
					tik.tick();
				seconden = 0;
			}
			else
				seconden++;
			tekstvak.setText(seconden + " seconden");
		}
	}
}