dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Creating GUI Game Of Life??

  1. #1
    Join Date
    Dec 2014
    Posts
    1

    Creating GUI Game Of Life??

    This is my code for the game of life GUI. I have created the GUI and the window pops up, however I don't understand how to get the Game of Life game to display within this window?

    can somebody provide some help please?



    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");
    label.setToolTipText("LIFE");
    label.setOpaque(true);
    label.setForeground(Color.BLUE);
    label.setVisible(true);
    add(label);


    }

    public static void main(String[] args) throws FileNotFoundException, InterruptedException
    {
    LifeMain lm = new LifeMain(); //Constructor calling the GUI class
    lm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    lm.setSize(800,600);
    lm.setAlwaysOnTop(true);
    lm.setVisible(true);
    lm.setBackground(Color.BLACK);

    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
    }

    }
    }

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,856

    Re: Creating GUI Game Of Life??

    Please edit your post and wrap the code in code tags.

    Where is the code for the Game of Life program?
    Norm

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)