import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

import java.io.*;
import javax.swing.JComponent;
import java.awt.Graphics;
import java.util.*;
import java.lang.Math;
import java.lang.System;
import java.lang.Object;
import java.util.Random;


public class CellMain
{
        public static void main(String[] args)
        {
//	    FileWriter outfile = new FileWriter( "coordinateData.data" );
//	    Random randomNumerGenerator = new Random();
//      double randomNumber;
      double x = 0.0;
      double y = 0.0;

                PictureFrame f = new PictureFrame();
                f.show();
        }
}



class CloseableFrame extends JFrame
{
        public CloseableFrame()
        {
                addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e)
                        {
                                System.exit(0);
                        }
                });
        }
}



class PictureFrame extends CloseableFrame
{
        public PictureFrame()
        {
                // set up frame
                myCellPanel = new CellPanel();
                setTitle("Cell Simulation");
                setSize(LENGTH, WIDTH);
                Container contentPane = getContentPane();

                // set up picture panel
                contentPane.add(myCellPanel, "Center");

        }

	private CellPanel myCellPanel;
	private final int LENGTH = 500;
	private final int WIDTH = 500;


}

class CellPanel extends JPanel {

	public CellPanel() {

		myCell = new cell(ID);
		Vector cellVector = new Vector();

		setBackground(Color.black);
		setForeground(Color.white);
	}


        public void paintComponent(Graphics g)
        {
                super.paintComponent(g);


               f = new Font("Serif", Font.BOLD, 10);
                g.setFont(f);

	  for(int i=0; i<30; i++)
          {
		int x, y;
          myCell.setSpeed(myCell.getSpeed());
          myCell.setDirection(myCell.getDirection());
          myCell.setRuntime(myCell.getRuntime());
          myCell.setStopFrame(myCell.getStopFrame());
          while(myCell.getCurrFrame() < myCell.getCurrSF())
          {

		x = myCell.getArrayX(myCell.getNextX());
		y = myCell.getArrayY(myCell.getNextY());

	if(x > getHeight())
	x -= getHeight();

	if(x < 0)
	x += getHeight();

	if(y > getWidth())
	y -= getWidth();

	if(y < 0)
	y += getWidth();


	g.drawString(ID, x, y);
	System.out.println( x +" and "+ y);

//         draw(g,this.getArrayX(x),this.getArrayY(y));
//         repaint();
         myCell.incrementFrame();
	}


      coordinates += myCell.getCurrX() + " " + myCell.getCurrY() + '\n';
      }

//      outfile.write( coordinates );
 //         outfile.flush();
  //    outfile.close();



	}
	private final int myLength = 400;
	private final int myWidth = 400;

	private Font f;
        private FontMetrics fm;
	private Vector cellVector;
	private cell myCell;
	private String ID = "o";
        String coordinates = new String("");



}



47



