• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating GUI for Game Of Life?

Arshdeep Soni
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code that I currently have for my game of life. I have created the GUI and a basic window comes up, however, i don't understand how to link the GUI and the game of life code so the game runs within the GUI window?

Can somebody provide some help and tips?

import java.io.*;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.FlowLayout; //Provides default layout managing
import javax.swing.JLabel;

public class LifeMain extends JFrame
private static JLabel label; //Creates a new label

public LifeMain()
super("Game Of Life");
setLayout(new FlowLayout());
label = new JLabel("Conway's Game Of Life");


public static void main(String[] args) throws FileNotFoundException, InterruptedException
LifeMain lm = new LifeMain(); //Constructor calling the GUI class

LifeGrid lg = new LifeGrid(9,9,"seed.txt"); //Creates an instance of LifeGrid called lg and fills the parameter
lg.show(); //Calls the show method

System.out.println(lg.toString()); //Prints the Height and Width from LifeGrid class
System.out.println("Grid Contents = " + lg.getContents(8,5) + "\nNeighbours = " + lg.Neighbours(2,2)); //x,y

int x = 1; //Initialize variable x
while(x<100) //Unless x goes above 100 do the following
x++; //Increments x by 1
System.out.println("\nNextGen = " + x); //Prints to screen x (Number of generation)
lg.Run(); //Calls the run method to run
Thread.sleep(1000); //Waits 1 second before executing next command


  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic