GUI Update

This commit is contained in:
Noah
2021-09-30 11:49:19 +02:00
parent 81da9e247a
commit 9478b37968
4 changed files with 64 additions and 9 deletions
+2 -2
View File
@@ -36,8 +36,8 @@ public class Draw extends JPanel {
super.paintComponent(g); super.paintComponent(g);
g2d = (Graphics2D) g; g2d = (Graphics2D) g;
float cellSizeX = 1024f / xSize; float cellSizeX = 800f / xSize;
float cellSizeY = 1024f / ySize; float cellSizeY = 800f / ySize;
if(ySize > xSize) if(ySize > xSize)
{ {
+6 -3
View File
@@ -11,20 +11,23 @@ public class Clock extends Thread{
public void start(Control control, GUI gui){ public void start(Control control, GUI gui){
Timer t = new Timer(); Timer t = new Timer();
TimerTask tt = new TimerTask() { TimerTask tt = new TimerTask() {
@Override @Override
public void run() { public void run() {
if (running){ if (running){
boolean[][] booleans = control.nextGen(); gui.showGrid(control.getCells());
gui.showGrid(booleans); control.nextGen();
} }
} }
}; };
t.scheduleAtFixedRate(tt, 1, 100000); t.scheduleAtFixedRate(tt, 1000, 3000);
} }
+32
View File
@@ -14,6 +14,9 @@ public class Control {
private boolean[][] cells; private boolean[][] cells;
private boolean[][] newcells; private boolean[][] newcells;
private int x = 0;
private int y = 0;
public void start() { public void start() {
@@ -67,10 +70,19 @@ public class Control {
private void generateTask1() { private void generateTask1() {
for (int x = 0; x < xSize; x++) { for (int x = 0; x < xSize; x++) {
for (int y = 0; y < ySize; y++) { 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[x][y] = true;
} }
} }
// cells[1][2] = true; // cells[1][2] = true;
// cells[2][2] = true; // cells[2][2] = true;
// cells[2][4] = 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) { private int aliveNeigbours(int x, int y) {
int count = 0; int count = 0;
+24 -4
View File
@@ -7,6 +7,8 @@ import game.StartMode;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
@@ -28,7 +30,7 @@ public class GUI {
private int xAxisSize = 6; private int xAxisSize = 6;
private JSlider xAxis; private JSlider xAxis;
private JLabel xAxisName; private JLabel xAxisName;
private JLabel xAxisLabel; private JTextField xAxisLabel;
private int yAxisSize = 6; private int yAxisSize = 6;
private JSlider yAxis; private JSlider yAxis;
private JLabel yAxisName; private JLabel yAxisName;
@@ -129,11 +131,29 @@ public class GUI {
xAxisName.setForeground(Color.decode("#121212")); xAxisName.setForeground(Color.decode("#121212"));
xAxisName.setVisible(true); xAxisName.setVisible(true);
xAxisLabel = new JLabel("6"); xAxisLabel = new JTextField("6");
xAxisLabel.setBackground(null);
xAxisLabel.setBorder(null);
xAxisLabel.setBounds(180, 80, 200, 30); xAxisLabel.setBounds(180, 80, 200, 30);
xAxisLabel.setFont(text); xAxisLabel.setFont(text);
xAxisLabel.setForeground(Color.decode("#121212")); xAxisLabel.setForeground(Color.decode("#121212"));
xAxisLabel.setVisible(true); 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; int yAxisMin = 6;
@@ -326,14 +346,14 @@ public class GUI {
jfGame = new JFrame(title); 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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfGame.setResizable(false); jfGame.setResizable(false);
float ratio = (float)(ySize) / (float)(xSize); float ratio = (float)(ySize) / (float)(xSize);
draw = new Draw(this.xSize, this.ySize, ratio); draw = new Draw(this.xSize, this.ySize, ratio);
draw.setBounds(0, 0, 1200, 1200); draw.setBounds(0, 0, 800, 800);
draw.setVisible(true); draw.setVisible(true);