Skip to content

Instantly share code, notes, and snippets.

@Shazambom
Created May 5, 2014 04:03
Show Gist options
  • Save Shazambom/150f4f2f10d90cfe4d8d to your computer and use it in GitHub Desktop.
Save Shazambom/150f4f2f10d90cfe4d8d to your computer and use it in GitHub Desktop.
The Main Class of my Game of Life program
import java.awt.*;
import java.awt.event.ActionListener;
import javax.swing.*;
/* Main issue currently:
* Applet Time
*/
public class Main
{
private static final int FRAME_WIDTH = 1000;
private static final int FRAME_HEIGHT = 750;
static Grid grid = new Grid();
static JButton[][] buttonGrid;
static ActionListener[][] listener;
//is the main function of the program. Sets up the frame, grid object, Button array, and
//the ActionListeners
public static void main ( String[] args ){
JFrame frame = new JFrame();
frame.setLayout(new GridLayout(grid.getX(),grid.getY()));
buttonGrid = new JButton[grid.getX()][grid.getY()];
listener = new ClickListener[grid.getX()][grid.getY()];
for(int i = 0; i < grid.getX(); i++){
for(int j = 0; j < grid.getY(); j++){
buttonGrid[i][j] = new JButton();
final JButton aButton = buttonGrid[i][j];
final ActionListener a = new ClickListener(i,j);
listener[i][j] = a;
aButton.addActionListener(a);
buttonGrid[i][j].setBackground(Color.lightGray);
frame.add(buttonGrid[i][j]);
}
}
frame.pack();
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JFrame startButton = new JFrame();
startButton.setLayout(new GridLayout(1,1));
startButton.setSize(200,100);
JButton start = new JButton("Start");
ActionListener sListener = new StartListener();
start.addActionListener(sListener);
startButton.add(start);
JButton step = new JButton("Step");
ActionListener stListener = new TimerListener();
step.addActionListener(stListener);
startButton.add(step);
startButton.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
startButton.setVisible(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment