Already asked this question, but not very well, so I am trying again. I am coding Conway's Game of Life in an Applet, I know, outdated and useless, but it's for a class. I have coded a 40x40 array of false items. I have coded a nextGen array that will be updated based on number of neighbors. I have coded what will happen to each cell based on number of living cells around it. I have coded clicking to make the selected cell be alive or dead based on what it currently is. And I have the code created for counting all cells near a specific cell. The only thing I need help with is transferring the array into the applet window as an a grid that can be clicked on to update cells from dead to alive.
This is part of the template we were given and what I have, I hope it's what you need to get started.
import java.awt.*;
import javax.swing.*;
import java.awt.event.MouseListener;
import java.util.Arrays;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class ForCs120 extends JApplet
{
JFrame myFrame = new JFrame();
JPanel aPanel = new JPanel();
JButton aButton = new JButton("Next Generation");
JButton clearButton = new JButton("Clear Board");
private boolean isLiving;
public void setAlive(boolean alive)
{
isLiving = alive;
}
public boolean isLiving()
{
return this.isLiving;
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
ButtonListener aButtonListener = new ButtonListener();
private class ClearButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
ClearButtonListener clear = new ClearButtonListener();
public void init()
{
JRootPane rootPane = this.getRootPane();
rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
this.addMouseListener(myListener);
aButton.setSize(150,150);
aButton.addActionListener(aButtonListener);
clearButton.addActionListener(clear);
myFrame.setSize(200,200);
aPanel.setSize(200,200);
aPanel.add(aButton);
aPanel.add(clearButton);
myFrame.add(aPanel);
myFrame.setVisible(true);
Comments
Post a Comment