import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;


public class InPanel extends Panel implements ActionListener {
    CoEffDet compton;
    Button starter, stopper, cleanplot;
    Label ampLab, lamLab, numLab;
    TextField ampText, lamText, numText;   
    int num;
    
   public InPanel(CoEffDet compton) {
	this.compton = compton;
	double l = compton.photon.lambda;
	double a = compton.photon.ampl;
	num = 1;
//	setBackground(Color.blue);
	starter = new Button("Run!");
	stopper = new Button("Freeze!");
	cleanplot = new Button("Clear plot");
	starter.setBackground(Color.green);
	starter.addActionListener(this);
	stopper.setBackground(Color.red);
	stopper.addActionListener(this);
	cleanplot.setBackground(Color.blue);
	cleanplot.addActionListener(this);
//	starter.setSize(50, 25);
	
//	setSize(compton.w, 30);
	setLayout(new GridLayout(3, 3)); 

	ampLab = new Label("The photon's amplitude:");
	lamLab = new Label("The wavelength:");
	numLab = new Label("Enter a number of photons:");
	ampText = new TextField(Double.toString(a));
	lamText = new TextField(Double.toString(l));
	numText = new TextField(Integer.toString(num));
	ampText.addActionListener(this);
	lamText.addActionListener(this);
	numText.addActionListener(this);

	add(starter); add(numLab); add(numText);
	add(stopper); add(ampLab); add(ampText);
	add(cleanplot); add(lamLab); add(lamText);
	
    }
    public void actionPerformed(ActionEvent ae) { 
	//ae can be a button pressed or textinput etc	
	String s = ae.getActionCommand();
	num = Integer.valueOf(numText.getText()).intValue();
	if(compton.numOfPh != num) {
	    compton.numOfPh = num;
//	compton.plotCanvas.resetPlot(); 
	}
	compton.photon.ampl = Double.valueOf(ampText.getText()).doubleValue();
	double lambda = Double.valueOf(lamText.getText()).doubleValue();	
	compton.photon.lambda = lambda;
	compton.photon.pre_lambda = lambda;
	
	if(s.equals("Run!") && num > 0) {
	    compton.shoot = true;	    
	}
	if(s.equals("Freeze!")) {
	    compton.shoot = false;
	}
	if(s.equals("Clear plot")) {
	    compton.plotCanvas.resetPlot();
	}
    }
}

