Fucking much stuff done.

This commit is contained in:
Noah
2021-12-14 23:22:01 +01:00
parent 546b538c99
commit 244a6ff839
14 changed files with 90891 additions and 512406 deletions
Binary file not shown.
+89275 -512383
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

File diff suppressed because one or more lines are too long
+2
View File
@@ -7,6 +7,8 @@ import java.util.List;
public class ReadDAO extends AbstractDAO {
public List<String> getAllGridNames() {
connect();
+13 -1
View File
@@ -8,9 +8,13 @@ import java.util.Arrays;
public class WriteDAO extends AbstractDAO{
public WriteDAO(){
createTable();
}
public void createTable(){
connect();
simpleStatement("create table if not exists GAME(id int auto_increment,name varchar not null,width int not null,height int not null,generation int not null,max_cellcount int not null,data clob);create unique index GAME_ID_UINDEX on GAME (id);create unique index GAME_NAME_UINDEX on GAME (name);");
simpleStatement("create table if not exists GAME(id int auto_increment,name varchar not null,width int not null,height int not null,generation int not null,max_cellcount int not null,data clob);");
disconnect();
}
@@ -34,4 +38,12 @@ public class WriteDAO extends AbstractDAO{
disconnect();
}
public void deleteEntry(String gridName){
connect();
simpleStatement("delete from GAME where Name = '"+gridName+"'");
disconnect();
}
}
+28 -3
View File
@@ -3,6 +3,7 @@ package gamecontrol;
import database.ReadDAO;
import database.WriteDAO;
import gui.windows.ControlWindow;
import gui.windows.DatabaseWindow;
import gui.windows.GameWindow;
import gui.windows.MenuWindow;
@@ -15,6 +16,9 @@ public class Control {
private MenuWindow menuWindow;
private GameWindow gameWindow;
private ControlWindow controlWindow;
private DatabaseWindow databaseWindow;
private Clock clock;
private ReadDAO readDAO;
private WriteDAO writeDAO;
@@ -66,8 +70,10 @@ public class Control {
calcSize();
gameWindow = new GameWindow(this, this.manual, this.xSize, this.ySize, this.width, this.height);
gameWindow = new GameWindow(this, this.xSize, this.ySize, this.width, this.height);
if (manual){
buildControlWindow();
}
clock.start();
@@ -404,6 +410,9 @@ public class Control {
public void buildControlWindow() {
controlWindow = new ControlWindow(this);
}
public void buildDatabaseWindow() {
databaseWindow = new DatabaseWindow(this);
}
public Point getGameWindowPos() {
return gameWindow.getPos();
@@ -417,13 +426,29 @@ public class Control {
return controlWindow;
}
public DatabaseWindow getDatabaseWindow() {
return databaseWindow;
}
public MenuWindow getMenuWindow() {
return menuWindow;
}
public void setVisibility(boolean value) {
public void setControlVisibility(boolean value) {
controlWindow.setVisibility(value);
}
public void setDatabaseVisibility(boolean value) {
databaseWindow.setVisibility(value);
}
public String[] getGameInfo(String gridName, String[] columnNames){
return readDAO.getGameInfo(gridName, columnNames);
}
public void deleteEntry(String gridName){
writeDAO.deleteEntry(gridName);
}
}
+4 -3
View File
@@ -47,7 +47,7 @@ public class ControlWindow extends GUI {
initPublicComponents();
controlWindow = new JFrame();
controlWindow = new JFrame(title + " Control");
controlWindow.getContentPane().setPreferredSize(new Dimension(width, height + (2 * offset)));
controlWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
@@ -392,7 +392,7 @@ public class ControlWindow extends GUI {
saveGridPlaceholder.setVisible(true);
saveGrid = new JTextField();
saveGrid.setDocument(new JTextFieldLimit(10));
saveGrid.setDocument(new JTextFieldLimit(15));
saveGrid.setFocusable(false);
saveGrid.setOpaque(false);
saveGrid.setBackground(null);
@@ -411,7 +411,7 @@ public class ControlWindow extends GUI {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if (checkName(saveGrid.getText())) {
if (checkName(saveGrid.getText() ) && getAllGrids().size() < 10) {
saveGridInDB(saveGrid.getText());
} else {
System.out.println("Vergeben");
@@ -419,6 +419,7 @@ public class ControlWindow extends GUI {
saveGrid.setText("");
saveGridPlaceholder.setVisible(true);
controlWindow.requestFocus();
}
}
+229
View File
@@ -0,0 +1,229 @@
package gui.windows;
import gamecontrol.Control;
import gui.fundamental.Hover;
import gui.fundamental.RoundedBorder;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;
public class DatabaseWindow extends GUI {
private JFrame databaseWindow;
private final Control control;
private JLabel[] names;
private JLabel[] widths;
private JLabel[] heights;
private JLabel[] generations;
private JLabel[] max_cellcounts;
private JButton[] deleteButtons;
private JLabel heading;
private JLabel name_heading;
private JLabel width_heading;
private JLabel height_heading;
private JLabel generation_heading;
private JLabel max_cellcount_heading;
private List<String> allGrids;
public DatabaseWindow(Control control) {
super(control);
this.control = control;
initPublicComponents();
databaseWindow = new JFrame();
databaseWindow.setTitle(this.title + " Database Control");
ImageIcon imageIcon = new ImageIcon("src/assets/icons/Icon.png");
databaseWindow.setIconImage(imageIcon.getImage());
databaseWindow.setUndecorated(false);
databaseWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
databaseWindow.setAutoRequestFocus(false);
databaseWindow.setLayout(null);
databaseWindow.setSize(1400, getAllGrids().size() * 75 + 200);
databaseWindow.setResizable(true);
databaseWindow.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
databaseWindow.dispose();
control.getMenuWindow().setVisibility(true);
control.getMenuWindow().setFocus();
}
});
initComponents();
addComponents();
databaseWindow.setLocationRelativeTo(null);
databaseWindow.setVisible(true);
databaseWindow.requestFocus();
}
private void initComponents() {
initHeading();
allGrids = control.getAllGrids();
names = new JLabel[allGrids.size()];
widths = new JLabel[allGrids.size()];
heights = new JLabel[allGrids.size()];
generations = new JLabel[allGrids.size()];
max_cellcounts = new JLabel[allGrids.size()];
deleteButtons = new JButton[allGrids.size()];
for (int i = 0; i < allGrids.size(); i++) {
String[] attributes = control.getGameInfo(allGrids.get(i), new String[]{"NAME", "WIDTH", "HEIGHT", "GENERATION", "MAX_CELLCOUNT"});
names[i] = new JLabel(attributes[0]);
names[i].setBounds(50, 75 * i + 150, 200, 30);
names[i].setFont(text);
names[i].setForeground(Color.decode("#121212"));
names[i].setVisible(true);
widths[i] = new JLabel(attributes[1]);
widths[i].setBounds(300, 75 * i + 150, 200, 30);
widths[i].setFont(text);
widths[i].setForeground(Color.decode("#121212"));
widths[i].setVisible(true);
heights[i] = new JLabel(attributes[2]);
heights[i].setBounds(550, 75 * i + 150, 200, 30);
heights[i].setFont(text);
heights[i].setForeground(Color.decode("#121212"));
heights[i].setVisible(true);
generations[i] = new JLabel(attributes[3]);
generations[i].setBounds(800, 75 * i + 150, 200, 30);
generations[i].setFont(text);
generations[i].setForeground(Color.decode("#121212"));
generations[i].setVisible(true);
max_cellcounts[i] = new JLabel(attributes[4]);
max_cellcounts[i].setBounds(1050, 75 * i + 150, 200, 30);
max_cellcounts[i].setFont(text);
max_cellcounts[i].setForeground(Color.decode("#121212"));
max_cellcounts[i].setVisible(true);
deleteButtons[i] = new JButton();
deleteButtons[i].setText("Delete");
deleteButtons[i].setFont(text);
deleteButtons[i].setForeground(Color.decode("#121212"));
deleteButtons[i].setBorderPainted(true);
deleteButtons[i].setFocusPainted(false);
deleteButtons[i].setContentAreaFilled(false);
deleteButtons[i].setBounds(1300, 75 * i + 150, 50, 30);
deleteButtons[i].setVisible(true);
deleteButtons[i].addMouseListener(new Hover());
deleteButtons[i].setBorder(new RoundedBorder(25));
deleteButtons[i].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
control.deleteEntry(attributes[0]);
update();
}
});
}
}
private void update(){
databaseWindow.getContentPane().removeAll();
databaseWindow.getContentPane().repaint();
initComponents();
databaseWindow.setSize(1400, getAllGrids().size() * 75 + 200);
addComponents();
}
private void initHeading() {
heading = new JLabel("Control over the Database");
heading.setBounds(50, 25, 300, 30);
heading.setFont(head);
heading.setForeground(Color.decode("#121212"));
heading.setVisible(true);
name_heading = new JLabel("Grid Name");
name_heading.setBounds(50, 75, 200, 30);
name_heading.setFont(sub_head);
name_heading.setForeground(Color.decode("#121212"));
name_heading.setVisible(true);
width_heading = new JLabel("Grid Width");
width_heading.setBounds(300, 75, 200, 30);
width_heading.setFont(sub_head);
width_heading.setForeground(Color.decode("#121212"));
width_heading.setVisible(true);
height_heading = new JLabel("Grid height");
height_heading.setBounds(550, 75, 200, 30);
height_heading.setFont(sub_head);
height_heading.setForeground(Color.decode("#121212"));
height_heading.setVisible(true);
generation_heading = new JLabel("Generation");
generation_heading.setBounds(800, 75, 200, 30);
generation_heading.setFont(sub_head);
generation_heading.setForeground(Color.decode("#121212"));
generation_heading.setVisible(true);
max_cellcount_heading = new JLabel("Max Cellcount");
max_cellcount_heading.setBounds(1050, 75, 200, 30);
max_cellcount_heading.setFont(sub_head);
max_cellcount_heading.setForeground(Color.decode("#121212"));
max_cellcount_heading.setVisible(true);
}
private void addComponents() {
databaseWindow.add(heading);
databaseWindow.add(name_heading);
databaseWindow.add(width_heading);
databaseWindow.add(height_heading);
databaseWindow.add(generation_heading);
databaseWindow.add(max_cellcount_heading);
for (int i = 0; i < names.length; i++) {
databaseWindow.add(names[i]);
databaseWindow.add(widths[i]);
databaseWindow.add(heights[i]);
databaseWindow.add(generations[i]);
databaseWindow.add(max_cellcounts[i]);
databaseWindow.add(deleteButtons[i]);
}
}
public void setVisibility(boolean value) {
databaseWindow.setVisible(value);
databaseWindow.requestFocus();
}
}
+4
View File
@@ -11,7 +11,9 @@ public abstract class GUI {
protected final int offset = 20;
protected Control control;
protected Font head;
protected Font sub_head;
protected Font text;
protected Font small;
protected boolean sliderLocked = false;
public GUI(Control control){
@@ -21,7 +23,9 @@ public abstract class GUI {
public void initPublicComponents() {
head = new Font("Segoe UI Light", Font.PLAIN, 24);
sub_head = new Font("Segoe UI Light", Font.PLAIN, 20);
text = new Font("Segoe UI Light", Font.PLAIN, 16);
small = new Font("Segoe UI Light", Font.PLAIN, 16);
}
+3 -7
View File
@@ -15,14 +15,13 @@ public class GameWindow extends GUI {
private final int cellCountX;
private final int cellCountY;
private String title;
private int width, height;
private final float ratio;
private boolean mouseLeft = false, mouseRight = false;
public GameWindow(Control control, boolean manual, int cellCountX, int cellCountY, int width, int height) {
public GameWindow(Control control, int cellCountX, int cellCountY, int width, int height) {
super(control);
this.cellCountX = cellCountX;
this.cellCountY = cellCountY;
@@ -30,6 +29,7 @@ public class GameWindow extends GUI {
initPublicComponents();
gameWindow = new JFrame(title + " | Generation: " + getGeneration());
gameWindow.requestFocus();
gameWindow.getContentPane().setPreferredSize(new Dimension(width + (2 * offset), height + (2 * offset)));
gameWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
@@ -37,10 +37,6 @@ public class GameWindow extends GUI {
ImageIcon imageIcon = new ImageIcon("src/assets/icons/Icon.png");
gameWindow.setIconImage(imageIcon.getImage());
if (manual){
control.buildControlWindow();
}
gameWindow.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
@@ -68,7 +64,7 @@ public class GameWindow extends GUI {
if (control.getControlWindow() == null){
control.buildControlWindow();
} else {
control.setVisibility(true);
control.setControlVisibility(true);
}
}
+74 -4
View File
@@ -3,6 +3,7 @@ package gui.windows;
import gamecontrol.Control;
import gui.fundamental.Hover;
import gui.fundamental.JTextFieldLimit;
import gui.fundamental.RoundedBorder;
import javax.swing.*;
@@ -42,6 +43,7 @@ public class MenuWindow extends GUI {
private MouseListener hover;
private JButton startButton;
private JButton helpButton;
private ImageIcon preview;
@@ -66,7 +68,42 @@ public class MenuWindow extends GUI {
menuWindow.setLayout(null);
menuWindow.setSize(752, 424);
menuWindow.setResizable(false);
menuWindow.setResizable(true);
menuWindow.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (e.isControlDown() && e.isAltDown() && e.getKeyCode() == KeyEvent.VK_D) {
menuWindow.setVisible(false);
if (control.getDatabaseWindow() == null){
control.buildDatabaseWindow();
} else {
control.setDatabaseVisibility(true);
}
}
}
@Override
public void keyReleased(KeyEvent e) {
}
});
menuWindow.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
menuWindow.requestFocus();
}
});
initComponents();
@@ -75,6 +112,7 @@ public class MenuWindow extends GUI {
menuWindow.setLocationRelativeTo(null);
menuWindow.setVisible(true);
}
private void initComponents() {
@@ -86,9 +124,30 @@ public class MenuWindow extends GUI {
initModeBox();
initStartButton();
initIMG();
initHelp();
}
private void initHelp(){
helpButton = new JButton();
helpButton.setText("?");
helpButton.setFont(small);
helpButton.setForeground(Color.decode("#121212"));
helpButton.setBorderPainted(true);
helpButton.setFocusPainted(false);
helpButton.setContentAreaFilled(false);
helpButton.setBorder(null);
helpButton.setBounds(692, 344, 40, 40);
helpButton.setVisible(true);
helpButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(menuWindow, "Press CTRL + AlT + D for Database Window or CTRL + ALT + C in Game Window to show Control Panel.");
}
});
}
private void initHeading(){
heading = new JLabel("Menu Panel");
heading.setFont(head);
@@ -122,7 +181,9 @@ public class MenuWindow extends GUI {
xAxisName.setForeground(Color.decode("#121212"));
xAxisName.setVisible(true);
xAxisLabel = new JTextField("6");
xAxisLabel = new JTextField();
xAxisLabel.setDocument(new JTextFieldLimit(4));
xAxisLabel.setText("6");
xAxisLabel.setBackground(null);
xAxisLabel.setBorder(null);
xAxisLabel.setBounds(180, 80, 200, 30);
@@ -185,7 +246,9 @@ public class MenuWindow extends GUI {
yAxisName.setForeground(Color.decode("#121212"));
yAxisName.setVisible(true);
yAxisLabel = new JTextField("6");
yAxisLabel = new JTextField();
yAxisLabel.setDocument(new JTextFieldLimit(4));
yAxisLabel.setText("6");
yAxisLabel.setBackground(null);
yAxisLabel.setBorder(null);
yAxisLabel.setBounds(180, 130, 200, 30);
@@ -248,7 +311,9 @@ public class MenuWindow extends GUI {
startCellsName.setForeground(Color.decode("#121212"));
startCellsName.setVisible(true);
startCellsLabel = new JTextField("6");
startCellsLabel = new JTextField();
startCellsLabel.setDocument(new JTextFieldLimit(7));
startCellsLabel.setText("6");
startCellsLabel.setBackground(null);
startCellsLabel.setBorder(null);
startCellsLabel.setBounds(180, 180, 200, 30);
@@ -363,6 +428,7 @@ public class MenuWindow extends GUI {
menuWindow.add(previewLabel);
menuWindow.add(modeName);
menuWindow.add(modeBox);
menuWindow.add(helpButton);
}
private void addComboBoxEntry(JComboBox<String> comboBox, String entry) {
@@ -370,6 +436,10 @@ public class MenuWindow extends GUI {
}
public void setVisibility(boolean visibility){
menuWindow.getContentPane().removeAll();
menuWindow.getContentPane().repaint();
initComponents();
addComponents();
menuWindow.setVisible(visibility);
}
+2 -5
View File
@@ -2,7 +2,9 @@ package main;
import database.ReadDAO;
import database.WriteDAO;
import gamecontrol.Control;
import gui.windows.DatabaseWindow;
import java.util.Arrays;
import java.util.List;
@@ -33,10 +35,5 @@ public class Main {
Control control = new Control();
control.start();
// ReadDAO readDAO = new ReadDAO();
// String[] x = readDAO.getGameInfo("test", new String[]{"MAX_CELLCOUNT", "GENERATION"});
// System.out.println(Arrays.toString(x));
}
}