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 Dimension size;      // Size of a cell
   private static int playerR;			//start row for the player
   private static int playerC;			//start col for the player
   public guipanel()
   {
      int r = 50;
      int c = 50;
      size = new Dimension(10,10);
      t = new Timer(DELAY, new Listener());
      con = new Conways(r,c);
      con.populate();
      setup(r,c);
      go = false;
      addMouseListener(new mouselisten());
      t.start();
   }
   private void setup(int r, int c)
   {
   
   }
   @Override
   public void paintComponent(Graphics g)
   {
      super.paintComponent(g);
      Object[][] l = con.toArray();
      int x = 0;
      int y = 0;
      int n = 0;
      for(int r = 0; r < con.numRows(); r++)
      {
         x = 0;
         for (int c = 0; c < con.numColumns(); c++)
         {
            n = con.getNeighbors(r,c);
            if(l[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.width,size.height);
            
            
            x+=size.width;
         }
         y+=size.height;
      }
   }
   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();
            con = null;
            con = concommon.fromFile(s);
            setup(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') con.wrap();
         else if (c == 'l') con.clear();
         // Add shift to change Y
         else if (c == '=') size.width++;
         else if (c == '+') size.height++;
         else if (c == '-') size.width--;
         else if (c == '_') size.height--;
         
         else if (c == ' ') go = !go;
   }
   public static void processmouse(MouseEvent e)
   {
      int mouseR = (e.getY()/size.width);
      int mouseC = (e.getX()/size.height);
      
      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);
      }
      System.out.println(mouseR+" "+mouseC);
   }
   public void mouseMoved(MouseEvent e)
   {
      int mouseR = (e.getY()/size.width);
      int mouseC = (e.getX()/size.height);
      if(mouseR >=0 && mouseC >= 0 && mouseR < con.numRows() && mouseC < con.numColumns())
      {
         playerR = mouseR;
         playerC = mouseC;
      }
   }
   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);
      }
   }

}
@@ -239,25 +239,20 @@
  static 
-Dimension
+byte
  size;  
@@ -259,12 +259,17 @@
     
+    
+ 
 // 
-S
+s
 ize 
@@ -309,24 +309,25 @@
 layerR;%09%09%09//
+ 
 start row fo
@@ -374,16 +374,17 @@
 rC;%09%09%09//
+ 
 start co
@@ -479,28 +479,10 @@
 e = 
-new Dimension(10,10)
+10
 ;%0A  
@@ -1408,26 +1408,13 @@
 size
-.width,size.height
+,size
 );%0A 
@@ -1457,22 +1457,16 @@
  x+=size
-.width
 ;%0A      
@@ -1486,23 +1486,16 @@
  y+=size
-.height
 ;%0A      
@@ -2329,29 +2329,28 @@
  // 
-Add shift to change Y
+Shift doesn't matter
 %0A   
@@ -2376,42 +2376,12 @@
  '='
-) size.width++;%0A         else if (
+ %7C%7C 
 c ==
@@ -2390,23 +2390,16 @@
 +') size
-.height
 ++;%0A    
@@ -2424,76 +2424,29 @@
  '-'
-) size.width--;%0A         else if (c == '_') size.height--;%0A         
+ %7C%7C c == '_') size--;
 %0A   
@@ -2564,38 +2564,32 @@
 = (e.getY()/size
-.width
 );%0A      int mou
@@ -2600,39 +2600,32 @@
 = (e.getX()/size
-.height
 );%0A      %0A      
@@ -2992,14 +2992,8 @@
 size
-.width
 );%0A 
@@ -3028,15 +3028,8 @@
 size
-.height
 );%0A 

Set size of board to single byte