This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Creating GUI for Game Of Life?  RSS feed

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 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; //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


I'm a lumberjack and I'm okay, I sleep all night and work all day. Lumberjack ad:
how do I do my own kindle-like thing - without amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!