/*
 * Created on Nov 27, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
import java.applet.Applet;
//import java.awt.Graphics;

import java.awt.*;
import javax.swing.*;
import java.awt.geom.Rectangle2D;
import java.util.*;
import java.beans.*;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;

import java.awt.BorderLayout;
import java.awt.Dimension;

import java.awt.event.*;

import java.lang.Thread;
import jone.*;
/**
 * @author brian
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class mytestapplet2 extends JApplet implements ActionListener {
	
	private int numSheep;
	 
	private JLabel sheepLabel; 
	private JTextField sheepText;
    
	private JLabel wolvesLabel;
	private JTextField wolvesText;
  
	private JLabel grassLabel;
	private JTextField grassText;
    private JButton continuePauseButton;
    //private JButton stopButton;
    private JButton restartButton;
    /* add a button for starting the run */
    
    private JTextField selectRatioText;
    private JTextField mutateProbText;
    private JTextField epochLengthText;
    private JTextField numEpochsText;
    private JTextField birthCostText;
    private JTextField overConsumptionPenaltyText;
    private JTextField foodBonusText;
    private JTextField mutateFracText;
    private JTextField runSpeedText;
    private JTextField percentToDisplayPerEpochText;
    private JTextField fitnessTimeWindowText;
    private JTextField fitnessWindowMaxText;
    private JTextField fitnessWindowMinText;
    
    private JLabel selectRatioLabel;
    private JLabel mutateProbLabel;
    private JLabel epochLengthLabel;
    private JLabel numEpochsLabel;
    private JLabel birthCostLabel;
    private JLabel overConsumptionPenaltyLabel;
    private JLabel foodBonusLabel;
    private JLabel mutateFracLabel;
    private JLabel runSpeedLabel;
    private JLabel percentToDisplayPerEpochLabel;
    private JLabel fitnessLabel;
    private JLabel timeLabel;
    private JLabel fitnessTimeWindowLabel;
    private JLabel fitnessWindowMaxLabel;
    private JLabel fitnessWindowMinLabel;
    
    
    private ArenaPanel drawingArea;
    private FitnessPlotPanel fitnessPanel;
    private int columnWidth = 3;
    private int spaceBTWLabelsAndText = 5;
    
    private JLabel fitnessPlotLabel;
    
	public void init() {
        //Create the text field and make it uneditable.
    	
		this.setSize(800,800);
		WindowUtilities.setNativeLookAndFeel();
        Container content = getContentPane();
        content.setBackground(Color.white);
        
        
        SpringLayout layout = new SpringLayout();
        content.setLayout(layout); 
        
        /* add num sheep text box */
        sheepLabel = new JLabel("<html><FONT COLOR=BLUE>Num Sheep #</FONT> </html>");
        layout.putConstraint(SpringLayout.WEST,sheepLabel,5,SpringLayout.WEST,
        		content);
        layout.putConstraint(SpringLayout.NORTH,sheepLabel,5,SpringLayout.NORTH,
        		content);
        content.add(sheepLabel);
        
        sheepText = new JTextField(columnWidth);
        layout.putConstraint(SpringLayout.WEST,sheepText,spaceBTWLabelsAndText,SpringLayout.EAST,
        		sheepLabel);
        layout.putConstraint(SpringLayout.NORTH,sheepText,0,SpringLayout.NORTH,
        		sheepLabel);
        sheepText.setEditable(true);
        sheepText.setEnabled(true);
        sheepText.setMaximumSize(new Dimension(10,10));
        content.add(sheepText);
       
        this.sheepText.setDocument(new PositiveIntegerDocument(4,0,1000)); //getDocument().addDocumentListener(this);
           
        /* wolves text box */
        wolvesLabel = new JLabel("<html><FONT COLOR=BLUE>Num Wolves #</FONT> </html>");
        layout.putConstraint(SpringLayout.WEST,wolvesLabel,spaceBTWLabelsAndText,SpringLayout.EAST,
        		sheepText);
        layout.putConstraint(SpringLayout.NORTH,wolvesLabel,0,SpringLayout.NORTH,
        		sheepLabel);
        content.add(wolvesLabel);
        
        wolvesText = new JTextField(columnWidth);
        layout.putConstraint(SpringLayout.WEST,wolvesText,spaceBTWLabelsAndText,SpringLayout.EAST,
        		wolvesLabel);
        layout.putConstraint(SpringLayout.NORTH,wolvesText,0,SpringLayout.NORTH,
        		wolvesLabel);
        wolvesText.setEditable(true);
        wolvesText.setEnabled(true);
        wolvesText.setMaximumSize(new Dimension(10,10));
        this.wolvesText.setDocument(new PositiveIntegerDocument(4,0,1000));
        content.add(wolvesText);
        
        /* grass text box */
        grassLabel = new JLabel("<html><FONT COLOR=BLUE>Num grass #</FONT> </html>");
        layout.putConstraint(SpringLayout.WEST,grassLabel,spaceBTWLabelsAndText,SpringLayout.EAST,
        		wolvesText);
        layout.putConstraint(SpringLayout.NORTH,grassLabel,0,SpringLayout.NORTH,
        		wolvesLabel);
        content.add(grassLabel);
        
        grassText = new JTextField(columnWidth);
        layout.putConstraint(SpringLayout.WEST,grassText,spaceBTWLabelsAndText,SpringLayout.EAST,
        		grassLabel);
        layout.putConstraint(SpringLayout.NORTH,grassText,0,SpringLayout.NORTH,
        		grassLabel);
        grassText.setEditable(true);
        grassText.setEnabled(true);
        grassText.setMaximumSize(new Dimension(10,10));
        content.add(grassText);
        this.grassText.setDocument(new PositiveIntegerDocument(4,0,1000));
        
        Dimension appletSize = this.getSize();
        int appletHeight = appletSize.height;
        int appletWidth = appletSize.width;
       // System.out.println("this applet is " + appletHeight + " "+ appletWidth);      
        drawingArea = new ArenaPanel();
        //drawingArea.  
        // Preferred height is irrelevant, since using WEST region
        drawingArea.setPreferredSize(new Dimension(drawingArea.width(), drawingArea.height()));
        drawingArea.setBorder(BorderFactory.createLineBorder (Color.blue, 2));
        drawingArea.setBackground(Color.white);
        
        layout.putConstraint(SpringLayout.NORTH,drawingArea,95,SpringLayout.NORTH,
        		content);
        layout.putConstraint(SpringLayout.WEST,drawingArea,15,SpringLayout.WEST,
        		content);
        content.add(drawingArea, BorderLayout.WEST);
        drawingArea.paint(drawingArea.getGraphics());
        setVisible(true);
        

        this.fitnessPanel = FitnessPlotPanel.getInstance();
        this.fitnessPanel.setPreferredSize(new Dimension(this.fitnessPanel.width(),
        		this.fitnessPanel.height()));
        this.fitnessPanel.setBorder(BorderFactory.createLineBorder (Color.black, 2));
        this.fitnessPanel.setBackground(Color.white);
        layout.putConstraint(SpringLayout.NORTH,fitnessPanel,75,SpringLayout.NORTH,
        		this.drawingArea);
        layout.putConstraint(SpringLayout.WEST,fitnessPanel,15,SpringLayout.EAST,
        		this.drawingArea);
        content.add(fitnessPanel, BorderLayout.WEST);
        this.fitnessPanel.paint(fitnessPanel.getGraphics());
        
        this.fitnessPlotLabel = new JLabel("<html><FONT COLOR=BLUE>Fitness of Best Agent vs Time </FONT> </html>");
        layout.putConstraint(SpringLayout.WEST,this.fitnessPlotLabel,
        		this.fitnessPanel.width()/2-65,SpringLayout.WEST,this.fitnessPanel);
    	   layout.putConstraint(SpringLayout.NORTH,this.fitnessPlotLabel,15,SpringLayout.SOUTH,
    	   		this.fitnessPanel); 
    	   content.add(this.fitnessPlotLabel);
        this.fitnessPanel.paint(this.fitnessPanel.getGraphics());
       
        this.fitnessWindowMaxLabel = new JLabel("<html><FONT COLOR=BLUE>Fitness Window Max </FONT> </html>");
        layout.putConstraint(SpringLayout.WEST,this.fitnessWindowMaxLabel,
        		this.spaceBTWLabelsAndText,SpringLayout.WEST,this.fitnessPanel);
    	 layout.putConstraint(SpringLayout.NORTH,this.fitnessWindowMaxLabel,45,SpringLayout.SOUTH,
    	   		this.fitnessPanel); 
    	content.add(this.fitnessWindowMaxLabel);
        
    	this.fitnessWindowMaxText = new JTextField(this.columnWidth);
    	initJTextField(this.fitnessWindowMaxText,content,new PositiveIntegerDocument(4,0,10000));
    	layout.putConstraint(SpringLayout.WEST,this.fitnessWindowMaxText,
        		this.spaceBTWLabelsAndText,SpringLayout.EAST,this.fitnessWindowMaxLabel);
    	 layout.putConstraint(SpringLayout.NORTH,this.fitnessWindowMaxText,0,SpringLayout.NORTH,
    	   		this.fitnessWindowMaxLabel); 
    	
    	 this.fitnessWindowMinLabel = new JLabel("<html><FONT COLOR=BLUE>Fitness Window Min </FONT> </html>");
         layout.putConstraint(SpringLayout.WEST,this.fitnessWindowMinLabel,
         		this.spaceBTWLabelsAndText,SpringLayout.EAST,this.fitnessWindowMaxText);
     	 layout.putConstraint(SpringLayout.NORTH,this.fitnessWindowMinLabel,0,SpringLayout.NORTH,
     	   		this.fitnessWindowMaxText); 
     	content.add(this.fitnessWindowMinLabel);
         
     	this.fitnessWindowMinText = new JTextField(this.columnWidth);
     	initJTextField(this.fitnessWindowMinText,content,new IntegerDocument(4));
     	layout.putConstraint(SpringLayout.WEST,this.fitnessWindowMinText,
         		this.spaceBTWLabelsAndText,SpringLayout.EAST,this.fitnessWindowMinLabel);
     	 layout.putConstraint(SpringLayout.NORTH,this.fitnessWindowMinText,0,SpringLayout.NORTH,
     	   		this.fitnessWindowMinLabel); 
    	 
     	 this.fitnessTimeWindowLabel = new JLabel("<html><FONT COLOR=BLUE> Time Window Max </FONT> </html>");
         layout.putConstraint(SpringLayout.WEST,this.fitnessTimeWindowLabel,
         		0,SpringLayout.WEST,this.fitnessWindowMaxLabel);
     	 layout.putConstraint(SpringLayout.NORTH,this.fitnessTimeWindowLabel,
     	 		2*this.spaceBTWLabelsAndText,SpringLayout.SOUTH,
     	   		this.fitnessWindowMaxLabel); 
     	content.add(this.fitnessTimeWindowLabel);
         
     	this.fitnessTimeWindowText = new JTextField(this.columnWidth);
     	initJTextField(this.fitnessTimeWindowText,content,new PositiveIntegerDocument(4,0,10000));
     	layout.putConstraint(SpringLayout.WEST,this.fitnessTimeWindowText,
         		this.spaceBTWLabelsAndText,SpringLayout.EAST,this.fitnessTimeWindowLabel);
     	 layout.putConstraint(SpringLayout.NORTH,this.fitnessTimeWindowText,0,SpringLayout.NORTH,
     	   		this.fitnessTimeWindowLabel); 
    	 
    	 
        this.restartButton = new JButton("Start/Restart");
        layout.putConstraint(SpringLayout.WEST,this.restartButton,spaceBTWLabelsAndText,SpringLayout.EAST,
        		this.grassText);
        layout.putConstraint(SpringLayout.NORTH,this.restartButton,0,SpringLayout.NORTH,
        		grassLabel);
       content.add(this.restartButton);
       this.restartButton.addActionListener(this);
       
       this.continuePauseButton = new JButton("Pause/Continue");
       layout.putConstraint(SpringLayout.WEST,this.continuePauseButton,spaceBTWLabelsAndText,SpringLayout.EAST,
    		this.restartButton);
	    layout.putConstraint(SpringLayout.NORTH,this.continuePauseButton,0,SpringLayout.NORTH,
	    		this.restartButton);
	   content.add(this.continuePauseButton);
	   this.continuePauseButton.addActionListener(this);
	 
	   this.mutateProbLabel = new JLabel("<html><FONT COLOR=BLUE>mutate prob</FONT> </html>");
	   layout.putConstraint(SpringLayout.WEST,this.mutateProbLabel,0,SpringLayout.WEST,
	   		this.sheepLabel);
	   layout.putConstraint(SpringLayout.NORTH,this.mutateProbLabel,30,SpringLayout.NORTH,
	   		this.sheepLabel); 
	   content.add(this.mutateProbLabel);
	   
	   this.mutateProbText = new JTextField(this.columnWidth);
		layout.putConstraint(SpringLayout.WEST,this.mutateProbText,spaceBTWLabelsAndText,SpringLayout.EAST,
				this.mutateProbLabel);
       layout.putConstraint(SpringLayout.NORTH,this.mutateProbText,0,SpringLayout.NORTH,
       		this.mutateProbLabel); 
       
		
       this.mutateProbText.setEditable(true);
       this.mutateProbText.setEnabled(true);
       this.mutateProbText.setMaximumSize(new Dimension(10,10));
       this.mutateProbText.setDocument(new DoubleDocument(4));
       content.add(this.mutateProbText);
	   
	   this.selectRatioLabel = new JLabel("<html><FONT COLOR=BLUE>% keep btw epochs </FONT> </html>"); //<html><FONT COLOR=BLUE>Num gss #</FONT> </html>");
	   layout.putConstraint(SpringLayout.WEST,this.selectRatioLabel,spaceBTWLabelsAndText,SpringLayout.EAST,
	   		this.mutateProbText);
	   layout.putConstraint(SpringLayout.NORTH,this.selectRatioLabel,0,SpringLayout.NORTH,
    		this.mutateProbText); 
	   
    	content.add(this.selectRatioLabel);
	   
    	this.selectRatioText = new JTextField(this.columnWidth);
    	initJTextField(this.selectRatioText,content,new DoubleDocument(5));
    	
    	layout.putConstraint(SpringLayout.WEST,this.selectRatioText,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.selectRatioLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.selectRatioText,0,SpringLayout.NORTH,
        		this.selectRatioLabel);
    	
    	this.numEpochsLabel = new JLabel("<html><FONT COLOR=BLUE>Num epochs </FONT> </html>");
    	layout.putConstraint(SpringLayout.WEST,this.numEpochsLabel,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.selectRatioText);
    	layout.putConstraint(SpringLayout.NORTH,this.numEpochsLabel,0,SpringLayout.NORTH,
        		this.selectRatioText);
    	content.add(this.numEpochsLabel);
    	
    	this.numEpochsText = new JTextField(this.columnWidth*2);
    	initJTextField(this.numEpochsText,content,new PositiveIntegerDocument(7,0,9999999));
    	
    	layout.putConstraint(SpringLayout.WEST,this.numEpochsText,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.numEpochsLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.numEpochsText,0,SpringLayout.NORTH,
        		this.numEpochsLabel);
    	
    	this.epochLengthLabel = new JLabel("<html><FONT COLOR=BLUE> epoch length </FONT> </html>");
    	layout.putConstraint(SpringLayout.WEST,this.epochLengthLabel,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.numEpochsText);
    	layout.putConstraint(SpringLayout.NORTH,this.epochLengthLabel,0,SpringLayout.NORTH,
        		this.numEpochsText);
    	content.add(this.epochLengthLabel);
    	
    	this.epochLengthText = new JTextField(this.columnWidth);
    	initJTextField(this.epochLengthText,content,new PositiveIntegerDocument(4,0,10000));
    	
    	layout.putConstraint(SpringLayout.WEST,this.epochLengthText,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.epochLengthLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.epochLengthText,0,SpringLayout.NORTH,
        		this.epochLengthLabel);
    	
    	
    	this.mutateFracLabel = new JLabel("<html><FONT COLOR=BLUE>mutate frac </FONT> </html>");
    	layout.putConstraint(SpringLayout.WEST,this.mutateFracLabel,0,SpringLayout.WEST,
    	   		this.sheepLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.mutateFracLabel,30,SpringLayout.NORTH,
        		this.mutateProbLabel);
    	content.add(this.mutateFracLabel);
    	
    	this.mutateFracText = new JTextField(this.columnWidth);
    	initJTextField(this.mutateFracText,content,new DoubleDocument(4));
    	
    	layout.putConstraint(SpringLayout.WEST,this.mutateFracText,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.mutateFracLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.mutateFracText,0,SpringLayout.NORTH,
        		this.mutateFracLabel);
    	
    	
    	this.foodBonusLabel = new JLabel("<html><FONT COLOR=BLUE>food bonus value </FONT> </html>");
    	layout.putConstraint(SpringLayout.WEST,this.foodBonusLabel,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.mutateFracText);
    	layout.putConstraint(SpringLayout.NORTH,this.foodBonusLabel,0,SpringLayout.NORTH,
        		this.mutateFracText);
    	content.add(this.foodBonusLabel);
    	
    	this.foodBonusText = new JTextField(this.columnWidth);
    	initJTextField(this.foodBonusText,content,new IntegerDocument(4));
    	
    	layout.putConstraint(SpringLayout.WEST,this.foodBonusText,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.foodBonusLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.foodBonusText,0,SpringLayout.NORTH,
        		this.foodBonusLabel);
    	
    	this.overConsumptionPenaltyLabel = new JLabel("<html><FONT COLOR=BLUE>overconsumption penaly </FONT> </html>");
    	layout.putConstraint(SpringLayout.WEST,this.overConsumptionPenaltyLabel,this.spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.foodBonusText);
    	layout.putConstraint(SpringLayout.NORTH,this.overConsumptionPenaltyLabel,0,SpringLayout.NORTH,
        		this.foodBonusText);
    	content.add(this.overConsumptionPenaltyLabel);
    	
    	this.overConsumptionPenaltyText = new JTextField(this.columnWidth);
    	initJTextField(this.overConsumptionPenaltyText,content,new IntegerDocument(4));
    	
    	layout.putConstraint(SpringLayout.WEST,this.overConsumptionPenaltyText,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.overConsumptionPenaltyLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.overConsumptionPenaltyText,0,SpringLayout.NORTH,
        		this.overConsumptionPenaltyLabel);
    	
    	this.birthCostLabel = new JLabel("<html><FONT COLOR=BLUE>birth cost </FONT> </html>");
    	layout.putConstraint(SpringLayout.WEST,this.birthCostLabel,this.spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.overConsumptionPenaltyText);
    	layout.putConstraint(SpringLayout.NORTH,this.birthCostLabel,0,SpringLayout.NORTH,
        		this.overConsumptionPenaltyText);
    	content.add(this.birthCostLabel); 
    	
    	this.birthCostText = new JTextField(this.columnWidth);
    	initJTextField(this.birthCostText,content,new IntegerDocument(4));
    	
    	layout.putConstraint(SpringLayout.WEST,this.birthCostText,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.birthCostLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.birthCostText,0,SpringLayout.NORTH,
        		this.birthCostLabel);
    	
    	this.runSpeedLabel = new JLabel("<html><FONT COLOR=BLUE>run speed </FONT> </html>");
    	layout.putConstraint(SpringLayout.WEST,this.runSpeedLabel,this.spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.drawingArea);
    	layout.putConstraint(SpringLayout.NORTH,this.runSpeedLabel,35,SpringLayout.NORTH,
        		this.birthCostLabel);
    	content.add(this.runSpeedLabel);
    	
    	this.runSpeedText = new JTextField(this.columnWidth);
    	initJTextField(this.runSpeedText,content,new PositiveIntegerDocument(4,0,100));
    	
    	layout.putConstraint(SpringLayout.WEST,this.runSpeedText,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.runSpeedLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.runSpeedText,0,SpringLayout.NORTH,
        		this.runSpeedLabel);
    	
    	this.percentToDisplayPerEpochLabel = new JLabel("<html><FONT COLOR=BLUE>percent to display </FONT> </html>");
    	layout.putConstraint(SpringLayout.WEST,this.percentToDisplayPerEpochLabel,0,SpringLayout.WEST,
    	   		this.runSpeedLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.percentToDisplayPerEpochLabel,35,SpringLayout.NORTH,
        		this.runSpeedLabel);
    	content.add(this.percentToDisplayPerEpochLabel);
    	
    	this.percentToDisplayPerEpochText = new JTextField(this.columnWidth);	
    	initJTextField(this.percentToDisplayPerEpochText,content,new PositiveIntegerDocument(4,0,100));
    	
    	layout.putConstraint(SpringLayout.WEST,this.percentToDisplayPerEpochText,spaceBTWLabelsAndText,SpringLayout.EAST,
    	   		this.percentToDisplayPerEpochLabel);
    	layout.putConstraint(SpringLayout.NORTH,this.percentToDisplayPerEpochText,0,SpringLayout.NORTH,
        		this.percentToDisplayPerEpochLabel);
    	
	   initValues();
    }

	private void initJLabel(JLabel textLabel, String label, JComponent jcomponent, Container content, 
			int westConstraint, int northConstraint, SpringLayout layout )
	{
		textLabel = new JLabel(label); // some text in here
		layout.putConstraint(SpringLayout.WEST,textLabel,westConstraint,SpringLayout.EAST,
				jcomponent);
        layout.putConstraint(SpringLayout.NORTH,textLabel,northConstraint,SpringLayout.NORTH,
        		jcomponent); 
        content.add(textLabel);
	}
	
	private void initJTextField(JTextField textField, Container content,
			Document document )
	{
		 
        textField.setEditable(true);
        textField.setEnabled(true);
        textField.setMaximumSize(new Dimension(10,10));
        textField.setDocument(document);
        content.add(textField);
	}
	
	public void initValues()
	{
		String [] args = {"50", "10", "2","0.01",".25",".3","10",
				"1000","-4","-10","10",".3", "90", "100"};
		this.sheepText.setText(args[0]);
		this.grassText.setText(args[2]);
		this.wolvesText.setText(args[1]);
		this.mutateProbText.setText(args[3]);
		this.selectRatioText.setText(args[4]);
		this.epochLengthText.setText(args[6]);
		this.numEpochsText.setText(args[7]);
		this.overConsumptionPenaltyText.setText(args[8]);
		this.birthCostText.setText(args[9]);
		this.foodBonusText.setText(args[10]);
		this.mutateFracText.setText(args[11]);
		this.runSpeedText.setText(args[12]);
		this.percentToDisplayPerEpochText.setText(args[13]);
		
		FitnessPlotPanel fpp = FitnessPlotPanel.getInstance();
		this.fitnessWindowMaxText.setText(fpp.getMaxFitnessWindow()+"");
		this.fitnessWindowMinText.setText(fpp.getMinFitnessWindow()+"");
		this.fitnessTimeWindowText.setText(fpp.getMaxTimeStepsWindow()+"");
		
	}
	
	public void start()
	{
		try {
		//for(int i = 0; i < 100; i++) {
			//this.update(this.getGraphics());
			//Thread.sleep(500);
			TestArena testArena = TestArena.getInstance();
			testArena.init(this.drawingArea.getGraphics()); 
			/* do i need to grab this object eveytime i want to update
			*/
		//}
		
		}
		catch (Exception e)
		{
			
		}
	}
    /** Handle the button click. */
    public void actionPerformed(ActionEvent e) {
	//Clear the text components.
    	TestArena ta = TestArena.getInstance();
    	/* passs the current parameter from the text fields in here */
    	Arena ar = Arena.getInstance();
    	ar.birthCost = Integer.parseInt(this.birthCostText.getText());
    	ar.epochLength = Integer.parseInt(this.epochLengthText.getText());
    	ar.foodBonus = Integer.parseInt(this.foodBonusText.getText());
    	ar.mutateFrac = Double.parseDouble(this.mutateFracText.getText());
    	ar.mutateRate = Double.parseDouble(this.mutateProbText.getText());
    	ar.overConsumptionPenalty = Integer.parseInt(this.overConsumptionPenaltyText.getText());
    	ar.selectedProportion = Double.parseDouble(this.selectRatioText.getText());
    	
    	FitnessPlotPanel fpp = FitnessPlotPanel.getInstance();
		fpp.setMaxFitnessWindow(Integer.parseInt(this.fitnessWindowMaxText.getText()));
		fpp.setMinFitnessWindow(Integer.parseInt(this.fitnessWindowMinText.getText())); 
		fpp.setMaxTimeStepsWindow(Integer.parseInt(this.fitnessTimeWindowText.getText()));
		/*ar.setNumSheepWolvesGrass(Integer.parseInt(this.sheepText.getText()),Integer.parseInt(this.wolvesText.getText()),
				Integer.parseInt(this.grassText.getText()));*/
		// set sheep and so forth
		
    	if((e.getActionCommand()).equalsIgnoreCase("Start/Restart")) {
    		ta.start(Integer.parseInt(this.sheepText.getText()),
    				Integer.parseInt(this.wolvesText.getText()),
    				Integer.parseInt(this.grassText.getText()),
					Double.parseDouble(this.mutateProbText.getText()),
					Double.parseDouble(this.selectRatioText.getText()),
					Double.parseDouble(this.mutateFracText.getText()),
					Integer.parseInt(this.epochLengthText.getText()),
					Integer.parseInt(this.numEpochsText.getText()),
					Integer.parseInt(this.foodBonusText.getText()),
					Integer.parseInt(this.birthCostText.getText()),
					Integer.parseInt(this.overConsumptionPenaltyText.getText()),
					Integer.parseInt(this.runSpeedText.getText()),
					Integer.parseInt(this.percentToDisplayPerEpochText.getText())
    		);
    	}
    	else if((e.getActionCommand()).equalsIgnoreCase("Pause/Continue"))
    		ta.stop(Double.parseDouble(this.mutateProbText.getText()),
					Double.parseDouble(this.selectRatioText.getText()),
					Double.parseDouble(this.mutateFracText.getText()),
					Integer.parseInt(this.epochLengthText.getText()),
					Integer.parseInt(this.numEpochsText.getText()),
					Integer.parseInt(this.foodBonusText.getText()),
					Integer.parseInt(this.birthCostText.getText()),
					Integer.parseInt(this.overConsumptionPenaltyText.getText()),
					Integer.parseInt(this.runSpeedText.getText()),
					Integer.parseInt(this.percentToDisplayPerEpochText.getText()));
    }
	
}



