import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.*;

public class TimePace implements ActionListener{
	public TimePace(PlantPanel tcp){
		this.tcp=tcp;
		delay=50;
		timer=new Timer(delay, this);
		gui= new Box(BoxLayout.X_AXIS);
		SpinnerNumberModel levelSpinner= new SpinnerNumberModel(delay, 0, 100, 2);
		levelSpinner.addChangeListener(new ChangeListener(){
			public void stateChanged(ChangeEvent e){
				SpinnerNumberModel sn=(SpinnerNumberModel)e.getSource();
				delay=sn.getNumber().intValue();
				timer.setDelay(delay);
			}
		});
		JLabel label= new JLabel(" Intervalo de tiempo:");
		gui.add(label);
		JSpinner spinner = new JSpinner(levelSpinner);
		label.setLabelFor(spinner);
		gui.add(spinner);
	}
	public void actionPerformed(ActionEvent e){
		tcp.simulationTick();
		//System.out.println("salida");
	}
	public Box getGUI() {
		return gui;
	}
	public void start(){
		timer.start();
	}
	private int delay;
	private Timer timer;
	private Box gui;
	private PlantPanel tcp;
}
