import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.SwingUtilities;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.*;
public class GUI extends JFrame implements MouseListener, ComponentListener{
Game gam = new Game();
JPanel mainPanel = new JPanel();
JPanel gPanel = new JPanel();
JPanel iPanel = new JPanel();
JLabel Gen = new JLabel("Generation: " + gam.getGen());
JLabel FPS = new JLabel("FPS: ");
public GUI(){
initUI();
}
public final void initUI(){
SpringLayout layout = new SpringLayout();
SpringLayout gLayout = new SpringLayout();
setTitle("Game Of Life");
setSize(620, 750);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
getContentPane().add(iPanel);
getContentPane().add(gPanel);
gPanel.setBounds(0, 0, getWidth(), (getHeight()/6)*5);
iPanel.setBounds(0, (getHeight()/6)*5, getWidth(), getHeight()/6);
gPanel.setLayout(gLayout);
iPanel.setLayout(layout);
addComponentListener(this);
gPanel.addMouseListener(this);
gPanel.setOpaque(true);
//---------------------------- ADDING THE drawComponent class ------------------------------------------------------
GridDraw drawG = new GridDraw();
gPanel.add(drawG);
gPanel.repaint();
gLayout.putConstraint(SpringLayout.NORTH, drawG, 20, SpringLayout.NORTH, gPanel);
gLayout.putConstraint(SpringLayout.EAST, drawG, 10, SpringLayout.EAST, gPanel);
JButton PButton = new JButton("Pause");
layout.putConstraint(SpringLayout.HORIZONTAL_CENTER, PButton, 0, SpringLayout.HORIZONTAL_CENTER, iPanel);
layout.putConstraint(SpringLayout.NORTH, Gen, 2, SpringLayout.NORTH, iPanel);
layout.putConstraint(SpringLayout.WEST, Gen, 0, SpringLayout.WEST, iPanel);
layout.putConstraint(SpringLayout.NORTH, FPS, 2, SpringLayout.SOUTH, Gen);
PButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
gam.pause();
repaint();
}
});
iPanel.add(PButton);
iPanel.add(Gen);
iPanel.add(FPS);
getRootPane().setDefaultButton(PButton);
gPanel.setVisible(true);
}