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

public class guipanel extends JPanel
{
   private static Conways con;
   private Timer t;
   private static final int DELAY = 100;
   private static boolean go;
   private static byte size;           // size of a cell
   private boolean wrap;
   private boolean border;
   private boolean one;
   
   public guipanel()
   {
      int r = 50;
      int c = 50;
      size = 10;
      t = new Timer(DELAY, new Listener());
      con = new Conways(r,c,null);
      con.populate();
      go = false;
      addMouseListener(new mouselisten());
      wrap = true;
      border = false;
      one = false;
      t.start();
   }
   @Override
   public void paintComponent(Graphics g)
   {
      super.paintComponent(g);
      int x = 5;
      int y = 5;
      int n = 0;
      for(int r = 0; r < con.numRows(); r++)
      {
         x = 5;
         for (int c = 0; c < con.numColumns(); c++)
         {
            n = con.getNeighbors(r,c);
            if(con.get(r,c) != null)
            {
               if (n > 3) g.setColor(Color.RED);
               else g.setColor(Color.BLACK);
            }
            else 
            {
               if (n == 3) g.setColor(Color.GREEN);
               else g.setColor(Color.WHITE);
            }
            g.fillRect(x,y,size,size);
            if (border)
            {
               if (g.getColor() == Color.WHITE) g.setColor(Color.BLACK);
               else g.setColor(Color.WHITE);
               g.drawRect(x,y,size,size);
            }
            x+=size;
         }
         y+=size;
      }
      if (!wrap)
      {
         Graphics2D g2 = (Graphics2D)g;
         g2.setColor(Color.BLUE);
         g2.setStroke(new BasicStroke(5));
         g2.drawRect(5,5,size*con.numColumns()+5,size*con.numRows()+5);
      }
   }
   private class Listener implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
         if (go) con.generation();
         repaint();
      }
   }
   public void processkeys(char c)
   {
         if (c == 'r')
         {
            go = false;
            String s = JOptionPane.showInputDialog("Read from File");
            removeAll();
            revalidate();
            repaint();
            wrap = true;
            con = concommon.fromFile(s,con.numRows(),con.numColumns());
         }
         else if (c == 'w')
         {
            go = false;
            String s = JOptionPane.showInputDialog("Write to File");
            concommon.toFile(con,s);
         }
         else if (c == 'p') wrap = con.wrap();
         else if (c == 'c') con.clear();
         else if (c == 'n')
         {
            go = false;
            con.populate();
            go = true;
         }
         else if (c == 's')
         {
            go = false;
            String s = JOptionPane.showInputDialog("New Dimensions");
            String[] z = s.split(" ");
            con = new Conways(Integer.parseInt(z[0]),Integer.parseInt(z[1]),null);
            con.populate();
         }
         else if (c == 'b') border = !border;
         // Shift doesn't matter
         else if (c == '=' || c == '+') size++;
         else if (c == '-' || c == '_') size--;
         else if (c == '.' || c == '>')
         {
            go = false;
            one = true;
         }
         else if (c == ',' || c == '<') 
         {
            one = false;
            go = true;
         }
         else if (c == ' ')
         {
            if (!one) go = !go;
            else con.generation();
         }
   }
   public static void processmouse(MouseEvent e)
   {
      int mouseR = (e.getY()/size);
      int mouseC = (e.getX()/size);
      
      if(mouseR >=0 && mouseC >= 0 && mouseR < con.numRows() && mouseC < con.numColumns())
      {
         if (e.getButton() == 1) con.set(mouseR,mouseC,new life());
         else if (e.getButton() == 3) con.set(mouseR,mouseC,null);
      }
   }

   public static class mouselisten implements MouseListener
   {
      public void mouseClicked(MouseEvent e) { }
      public void	mouseEntered(MouseEvent e) { }
      public void	mouseExited(MouseEvent e)  { }
      public void	mousePressed(MouseEvent e) { }
      public void	mouseReleased(MouseEvent e)
      {
         processmouse(e);
      }
   }

}
@@ -354,16 +354,64 @@
 an one;%0A
+   private String rulefile; // Name of rulefile%0A
    %0A   p
@@ -557,20 +557,24 @@
 ays(r,c,
-null
+rulefile
 );%0A     
@@ -999,32 +999,117 @@
 c++)%0A         %7B%0A
+            Integer%5B%5D b = con.getBorn();%0A            Integer%5B%5D s = con.getSurvive();%0A
             n = 
@@ -1159,17 +1159,17 @@
 et(r,c) 
-!
+=
 = null)%0A
@@ -1203,16 +1203,58 @@
   if
- (n %3E 3)
+(con.isBorn(n))%0A               %7B%0A                 
  g.s
@@ -1271,14 +1271,33 @@
 lor.
+G
 RE
-D
+EN
 );%0A
+               %7D%0A
     
@@ -1321,37 +1321,37 @@
 .setColor(Color.
-BLACK
+WHITE
 );%0A            %7D
@@ -1404,42 +1404,103 @@
   if
- (n == 3) g.setColor(Color.GREEN);
+(con.isSurvive(n))%0A               %7B%0A                  g.setColor(Color.BLACK);%0A               %7D
 %0A   
@@ -1525,37 +1525,35 @@
 .setColor(Color.
-WHITE
+RED
 );%0A            %7D
@@ -2607,16 +2607,25 @@
 olumns()
+,rulefile
 );%0A     
@@ -3271,20 +3271,24 @@
 t(z%5B1%5D),
-null
+rulefile
 );%0A     

Add rulefil as well as isBorn and isSurvive