diff --git a/src/draw/Draw.java b/src/draw/Draw.java index 45e9964..a196229 100644 --- a/src/draw/Draw.java +++ b/src/draw/Draw.java @@ -36,8 +36,8 @@ public class Draw extends JPanel { super.paintComponent(g); g2d = (Graphics2D) g; - float cellSizeX = 1024f / xSize; - float cellSizeY = 1024f / ySize; + float cellSizeX = 800f / xSize; + float cellSizeY = 800f / ySize; if(ySize > xSize) { diff --git a/src/game/Clock.java b/src/game/Clock.java index 206abde..d848205 100644 --- a/src/game/Clock.java +++ b/src/game/Clock.java @@ -11,20 +11,23 @@ public class Clock extends Thread{ public void start(Control control, GUI gui){ + + Timer t = new Timer(); TimerTask tt = new TimerTask() { @Override public void run() { if (running){ - boolean[][] booleans = control.nextGen(); - gui.showGrid(booleans); + gui.showGrid(control.getCells()); + control.nextGen(); + } } }; - t.scheduleAtFixedRate(tt, 1, 100000); + t.scheduleAtFixedRate(tt, 1000, 3000); } diff --git a/src/game/Control.java b/src/game/Control.java index e12382c..f8f756d 100644 --- a/src/game/Control.java +++ b/src/game/Control.java @@ -14,6 +14,9 @@ public class Control { private boolean[][] cells; private boolean[][] newcells; + private int x = 0; + private int y = 0; + public void start() { @@ -67,10 +70,19 @@ public class Control { private void generateTask1() { for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { + cells[x][y] = false; + } + } + + for (int x = 1; x < 7; x++) { + for (int y = 1; y < 7; y++) { cells[x][y] = true; } } + + + // cells[1][2] = true; // cells[2][2] = true; // cells[2][4] = true; @@ -149,6 +161,26 @@ public class Control { } + public boolean[][] nextGen_GridTest(){ + for (int x = 0; x < xSize; x++) { + for (int y = 0; y < ySize; y++) { + cells[x][y] = false; + } + } + + + + if (x == xSize){ x = 0; y++;} + if (y == ySize) y = 0; + + + + cells[x][y] = true; + x++; + + return cells; + } + private int aliveNeigbours(int x, int y) { int count = 0; diff --git a/src/gui/GUI.java b/src/gui/GUI.java index 5d5af23..e9212e6 100644 --- a/src/gui/GUI.java +++ b/src/gui/GUI.java @@ -7,6 +7,8 @@ import game.StartMode; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import java.awt.*; import java.awt.event.*; @@ -28,7 +30,7 @@ public class GUI { private int xAxisSize = 6; private JSlider xAxis; private JLabel xAxisName; - private JLabel xAxisLabel; + private JTextField xAxisLabel; private int yAxisSize = 6; private JSlider yAxis; private JLabel yAxisName; @@ -129,11 +131,29 @@ public class GUI { xAxisName.setForeground(Color.decode("#121212")); xAxisName.setVisible(true); - xAxisLabel = new JLabel("6"); + xAxisLabel = new JTextField("6"); + xAxisLabel.setBackground(null); + xAxisLabel.setBorder(null); xAxisLabel.setBounds(180, 80, 200, 30); xAxisLabel.setFont(text); xAxisLabel.setForeground(Color.decode("#121212")); xAxisLabel.setVisible(true); + xAxisLabel.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + System.out.println(xAxisLabel.getText()); + } + + @Override + public void removeUpdate(DocumentEvent e) { + + } + + @Override + public void changedUpdate(DocumentEvent e) { + + } + }); int yAxisMin = 6; @@ -326,14 +346,14 @@ public class GUI { jfGame = new JFrame(title); - jfGame.getContentPane().setPreferredSize(new Dimension(1600, 1600)); + jfGame.getContentPane().setPreferredSize(new Dimension(1000, 1000)); jfGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jfGame.setResizable(false); float ratio = (float)(ySize) / (float)(xSize); draw = new Draw(this.xSize, this.ySize, ratio); - draw.setBounds(0, 0, 1200, 1200); + draw.setBounds(0, 0, 800, 800); draw.setVisible(true);