GUI Class Abstract.

This commit is contained in:
Noah
2021-12-14 18:44:26 +01:00
parent bed59d4ecc
commit 546b538c99
13 changed files with 26646 additions and 323 deletions
Binary file not shown.
File diff suppressed because it is too large Load Diff
-3
View File
@@ -1,7 +1,5 @@
package gamecontrol;
import gui.control.GUI;
import java.util.Timer;
import java.util.TimerTask;
@@ -59,7 +57,6 @@ public class Clock extends Thread {
this.running = running;
}
public int getVelocity() {
return velocity;
}
+70 -42
View File
@@ -2,14 +2,19 @@ package gamecontrol;
import database.ReadDAO;
import database.WriteDAO;
import gui.control.GUI;
import gui.windows.ControlWindow;
import gui.windows.GameWindow;
import gui.windows.MenuWindow;
import java.awt.*;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class Control {
private GUI gui;
private MenuWindow menuWindow;
private GameWindow gameWindow;
private ControlWindow controlWindow;
private Clock clock;
private ReadDAO readDAO;
private WriteDAO writeDAO;
@@ -26,29 +31,30 @@ public class Control {
private int width, height;
private boolean mouseLocked;
private boolean manual;
public void start() {
clock = new Clock(this);
gui = new GUI(this);
readDAO = new ReadDAO();
writeDAO = new WriteDAO();
gui.createMenuWindow();
this.readDAO = new ReadDAO();
this.writeDAO = new WriteDAO();
menuWindow = new MenuWindow(this);
}
public void startGame() {
clock.start();
}
public void buildGameWindow(int xSize, int ySize, int cellCount, String startMode) {
manual = false;
switch (startMode) {
case "Randomized" -> {
generateRandomized(xSize, ySize, cellCount);
}
case "Manuel" -> {
setManual(true);
buildManuelGame(xSize, ySize, cellCount);
}
default -> {
@@ -60,13 +66,10 @@ public class Control {
calcSize();
gui.createGameWindow(this.xSize, this.ySize, this.width, this.height);
gameWindow = new GameWindow(this, this.manual, this.xSize, this.ySize, this.width, this.height);
if (startMode == "Manuel"){
gui.buildControlWindow();
}
startGame();
clock.start();
}
@@ -99,7 +102,7 @@ public class Control {
}
private void getFromDatabase(String name){
private void getFromDatabase(String name) {
cells = readDAO.getGrid(name);
gen = Integer.parseInt(readDAO.getGameInfo(name, "GENERATION"));
@@ -147,7 +150,7 @@ public class Control {
}
}
public void saveFirstGrid(){
public void saveFirstGrid() {
for (int x = 0; x < this.xSize; x++) {
for (int y = 0; y < this.ySize; y++) {
startingCells[x][y] = cells[x][y];
@@ -155,7 +158,7 @@ public class Control {
}
}
private void resetCells(){
private void resetCells() {
for (int x = 0; x < this.xSize; x++) {
for (int y = 0; y < this.ySize; y++) {
cells[x][y] = startingCells[x][y];
@@ -194,7 +197,7 @@ public class Control {
cells[x][y] = newcells[x][y];
}
}
gui.updateGameWindowTitle(gen);
gameWindow.updateTitle(gen);
}
public void nextGenLight() {
@@ -224,15 +227,15 @@ public class Control {
}
}
public void previousGen(){
if(gen > 0) {
public void previousGen() {
if (gen > 0) {
resetCells();
syncCells();
for (int i = 0; i < gen - 1; i++) {
nextGenLight();
}
gen--;
gui.updateGameWindowTitle(gen);
gameWindow.updateTitle(gen);
}
}
@@ -257,13 +260,6 @@ public class Control {
return ThreadLocalRandom.current().nextInt(min, max);
}
public void showGrid(boolean[][] grid) {
gui.showGrid(grid);
}
public void setVisibility(boolean value) {
gui.setVisibility(value);
}
public void setCell(int mouseX, int mouseY, boolean value, int offset) {
@@ -285,7 +281,7 @@ public class Control {
cells[x][y] = value;
syncCells();
gui.showGrid(cells);
gameWindow.showGrid(cells);
}
private void calcSize() {
@@ -325,14 +321,14 @@ public class Control {
clock.setRunning(state);
}
public void setVelocity(int velocity) {
clock.setVelocity(velocity);
}
public int getVelocity() {
return clock.getVelocity();
}
public void setVelocity(int velocity) {
clock.setVelocity(velocity);
}
public boolean isMouseLocked() {
return mouseLocked;
}
@@ -359,43 +355,75 @@ public class Control {
}
}
public int getGeneration(){
public int getGeneration() {
return gen;
}
public void jump2Gen(int wantedtGen){
if (wantedtGen <= gen){
public void jump2Gen(int wantedtGen) {
if (wantedtGen <= gen) {
resetCells();
syncCells();
int counter = ((gen - wantedtGen) / (wantedtGen + 1) );
int counter = ((gen - wantedtGen) / (wantedtGen + 1));
for (int i = 0; i < wantedtGen; i++) {
nextGenLight();
gen = gen - counter;
gui.updateGameWindowTitle(gen);
gameWindow.updateTitle(gen);
}
gen = wantedtGen;
gui.updateGameWindowTitle(gen);
gameWindow.updateTitle(gen);
} else {
multipleGenSkip(wantedtGen - gen);
}
}
public List<String> getAllGrids(){
public List<String> getAllGrids() {
return readDAO.getAllGridNames();
}
public void saveGridInDB(String gridName){
public void saveGridInDB(String gridName) {
writeDAO.saveGrid(this.cells, gridName, this.gen, this.cellCount);
}
public boolean checkName(String name){
public boolean checkName(String name) {
return readDAO.checkName(name);
}
public boolean isManual() {
return manual;
}
public void setManual(boolean manual) {
this.manual = manual;
}
public void buildControlWindow() {
controlWindow = new ControlWindow(this);
}
public Point getGameWindowPos() {
return gameWindow.getPos();
}
public void showGrid(boolean[][] grid) {
gameWindow.showGrid(grid);
}
public ControlWindow getControlWindow() {
return controlWindow;
}
public MenuWindow getMenuWindow() {
return menuWindow;
}
public void setVisibility(boolean value) {
controlWindow.setVisibility(value);
}
}
-167
View File
@@ -1,167 +0,0 @@
package gui.control;
import gamecontrol.Control;
import gui.windows.ControlWindow;
import gui.windows.GameWindow;
import gui.windows.MenuWindow;
import java.awt.*;
import java.util.List;
public class GUI {
private final String title = "Conway's game if Live";
private final Control control;
private Font head;
private Font text;
private boolean sliderLocked = false;
private final int offset = 20;
private MenuWindow menuWindow;
private GameWindow gameWindow;
private ControlWindow controlWindow;
public GUI(Control control){
this.control = control;
initPublicComponents();
}
public void initPublicComponents(){
head = new Font("Segoe UI Light", Font.PLAIN, 24);
text = new Font("Segoe UI Light", Font.PLAIN, 16);
}
public void createMenuWindow(){
menuWindow = new MenuWindow(title, this);
}
public void createGameWindow(int cellCountX, int cellCountY, int width, int height){
gameWindow = new GameWindow(title, this, cellCountX, cellCountY, width, height, offset);
}
public void createControlWindow(){
controlWindow = new ControlWindow(gameWindow, this, offset);
}
public void showGrid(boolean[][] grid){
gameWindow.showGrid(grid);
}
public void buildGameWindow(int xSize, int ySize, int cellCount, String startMode){
control.buildGameWindow(xSize, ySize, cellCount, startMode);
}
public void buildControlWindow(){
createControlWindow();
}
public void setCell(int mouseX, int mouseY, boolean value){
control.setCell(mouseX, mouseY, value, offset);
}
public void setRunning(boolean state){
control.setRunning(state);
}
public boolean isRunning(){
return control.isRunning();
}
public MenuWindow getMenuWindow(){
return menuWindow;
}
public void setVelocity(int velocity){
control.setVelocity(velocity);
}
public Font getHead() {
return head;
}
public Font getText() {
return text;
}
public boolean isSliderLocked() {
return sliderLocked;
}
public void setSliderLocked(boolean sliderLocked) {
this.sliderLocked = sliderLocked;
}
public void nextGen(){
control.nextGen();
}
public boolean[][] getCells(){ return control.getCells(); }
public boolean isMouseLocked(){
return control.isMouseLocked();
}
public void setMouseLocked(boolean value){
control.setMouseLocked(value);
}
public void clearGrid(){ control.clearGrid(); }
public void multipleGenSkip(int generations){
control.multipleGenSkip(generations);
}
public int getGeneration(){
return control.getGeneration();
}
public void updateGameWindowTitle(int gen){
gameWindow.updateTitle(gen);
}
public int getVelocity(){
return control.getVelocity();
}
public void saveFirstGrid(){
control.saveFirstGrid();
}
public void previousGen(){
control.previousGen();
}
public void jump2Gen(int wantedtGen){
control.jump2Gen(wantedtGen);
}
public void saveGridInDB(String gridName){
control.saveGridInDB(gridName);
}
public List<String> getAllGrids(){
return control.getAllGrids();
}
public boolean checkName(String name){
return control.checkName(name);
}
//TODO: Delet this Methods. Those are shit.
public void setVisibility(boolean value){
controlWindow.setVisibility(value);
}
public ControlWindow getControlWindow() {
return controlWindow;
}
}
@@ -1,4 +1,4 @@
package gui.basics;
package gui.fundamental;
import javax.swing.*;
import java.awt.*;
@@ -1,4 +1,4 @@
package gui.basics;
package gui.fundamental;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
@@ -1,4 +1,4 @@
package gui.basics;
package gui.fundamental;
import javax.swing.border.Border;
import java.awt.*;
+46 -58
View File
@@ -1,9 +1,9 @@
package gui.windows;
import gui.control.GUI;
import gui.basics.Hover;
import gui.basics.JTextFieldLimit;
import gui.basics.RoundedBorder;
import gamecontrol.Control;
import gui.fundamental.Hover;
import gui.fundamental.JTextFieldLimit;
import gui.fundamental.RoundedBorder;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
@@ -13,13 +13,10 @@ import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.*;
public class ControlWindow {
public class ControlWindow extends GUI {
private final int width = 400, height = 800;
private final Font head;
private final Font text;
private final JFrame controlWindow;
private JLabel heading;
private JButton toggleGame;
@@ -43,23 +40,19 @@ public class ControlWindow {
private JLabel velocitySliderName;
private JTextField velocitySliderLabel;
private final GUI gui;
public ControlWindow(GameWindow gameWindow, GUI gui, int offset) {
this.gui = gui;
this.head = gui.getHead();
this.text = gui.getText();
public ControlWindow(Control control) {
super(control);
velocity = 500;
initPublicComponents();
controlWindow = new JFrame();
controlWindow.getContentPane().setPreferredSize(new Dimension(width, height + (2 * offset)));
controlWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
controlWindow.setResizable(false);
controlWindow.setLocation(gameWindow.getPos().x - (width + offset), gameWindow.getPos().y);
controlWindow.setLocation(control.getGameWindowPos().x - (width + offset), control.getGameWindowPos().y);
controlWindow.setLayout(null);
ImageIcon imageIcon = new ImageIcon("src/assets/icons/Icon.png");
@@ -117,14 +110,14 @@ public class ControlWindow {
velocitySlider.setBounds(120, 110, 230, 20);
velocitySlider.setFont(text);
velocitySlider.setForeground(Color.decode("#121212"));
velocitySlider.setValue(gui.getVelocity());
velocitySlider.setValue(getVelocity());
velocitySlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!gui.isSliderLocked()) {
if (!isSliderLocked()) {
velocity = velocitySlider.getValue();
velocitySliderLabel.setText(String.valueOf(velocity));
gui.setVelocity(velocity);
setVelocity(velocity);
}
}
});
@@ -137,7 +130,7 @@ public class ControlWindow {
velocitySliderName.setForeground(Color.decode("#121212"));
velocitySliderName.setVisible(true);
velocitySliderLabel = new JTextField(String.valueOf(gui.getVelocity()));
velocitySliderLabel = new JTextField(String.valueOf(getVelocity()));
velocitySliderLabel.setBackground(null);
velocitySliderLabel.setBorder(null);
velocitySliderLabel.setBounds(120, 80, 200, 30);
@@ -156,12 +149,12 @@ public class ControlWindow {
@Override
public void insertUpdate(DocumentEvent e) {
gui.setSliderLocked(true);
setSliderLocked(true);
String s = velocitySliderLabel.getText();
velocitySlider.setValue(Integer.parseInt(s));
velocity = velocitySlider.getValue();
gui.setVelocity(velocity);
gui.setSliderLocked(false);
setVelocity(velocity);
setSliderLocked(false);
}
@Override
@@ -196,19 +189,19 @@ public class ControlWindow {
toggleGame.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (gui.getGeneration() == 0) {
gui.saveFirstGrid();
if (getGeneration() == 0) {
saveFirstGrid();
}
if (!gui.isRunning()) {
gui.setMouseLocked(true);
if (!isRunning()) {
setMouseLocked(true);
saveGrid.setFocusable(false);
updateLockedMouse();
} else {
saveGrid.setFocusable(true);
}
gui.setRunning(!gui.isRunning());
setRunning(!isRunning());
updateToggleButton();
gui.setVelocity(velocity);
setVelocity(velocity);
}
});
@@ -230,12 +223,12 @@ public class ControlWindow {
nextGenButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!gui.isRunning()) {
if (gui.getGeneration() == 0) {
gui.saveFirstGrid();
if (!isRunning()) {
if (getGeneration() == 0) {
saveFirstGrid();
}
gui.nextGen();
gui.showGrid(gui.getCells());
nextGen();
control.showGrid(getCells());
}
}
});
@@ -256,9 +249,9 @@ public class ControlWindow {
previousGenButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!gui.isRunning()) {
gui.previousGen();
gui.showGrid(gui.getCells());
if (!isRunning()) {
previousGen();
control.showGrid(getCells());
}
}
});
@@ -278,8 +271,8 @@ public class ControlWindow {
lockMouse.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!gui.isRunning()) {
gui.setMouseLocked(!gui.isMouseLocked());
if (!isRunning()) {
setMouseLocked(!isMouseLocked());
updateLockedMouse();
}
}
@@ -302,9 +295,9 @@ public class ControlWindow {
clearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!gui.isRunning()) {
gui.clearGrid();
gui.showGrid(gui.getCells());
if (!isRunning()) {
clearGrid();
control.showGrid(getCells());
}
}
});
@@ -326,9 +319,9 @@ public class ControlWindow {
multipleGenSkipButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!gui.isRunning()) {
gui.multipleGenSkip(Integer.parseInt(multipleGenSkipLable.getText()));
gui.showGrid(gui.getCells());
if (!isRunning()) {
multipleGenSkip(Integer.parseInt(multipleGenSkipLable.getText()));
control.showGrid(getCells());
}
}
});
@@ -366,9 +359,9 @@ public class ControlWindow {
jump2GenButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!gui.isRunning()) {
gui.jump2Gen(Integer.parseInt(jump2GenLable.getText()));
gui.showGrid(gui.getCells());
if (!isRunning()) {
jump2Gen(Integer.parseInt(jump2GenLable.getText()));
control.showGrid(getCells());
}
}
});
@@ -418,8 +411,8 @@ public class ControlWindow {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if (gui.checkName(saveGrid.getText())) {
gui.saveGridInDB(saveGrid.getText());
if (checkName(saveGrid.getText())) {
saveGridInDB(saveGrid.getText());
} else {
System.out.println("Vergeben");
}
@@ -470,7 +463,7 @@ public class ControlWindow {
}
private void updateToggleButton() {
if (!gui.isRunning()) {
if (!isRunning()) {
toggleGame.setText("Resume Game");
} else {
toggleGame.setText("Pause Game");
@@ -479,7 +472,7 @@ public class ControlWindow {
private void updateLockedMouse() {
if (!gui.isMouseLocked()) {
if (!isMouseLocked()) {
lockMouse.setText("Lock Mouse");
} else {
lockMouse.setText("Unlock Mouse");
@@ -489,9 +482,4 @@ public class ControlWindow {
public void dispose() {
controlWindow.dispose();
}
public void setVelocity(int velocity) {
gui.setVelocity(velocity);
}
}
+115
View File
@@ -0,0 +1,115 @@
package gui.windows;
import gamecontrol.Control;
import java.awt.*;
import java.util.List;
public abstract class GUI {
protected final String title = "Conway's game if Live";
protected final int offset = 20;
protected Control control;
protected Font head;
protected Font text;
protected boolean sliderLocked = false;
public GUI(Control control){
this.control = control;
}
public void initPublicComponents() {
head = new Font("Segoe UI Light", Font.PLAIN, 24);
text = new Font("Segoe UI Light", Font.PLAIN, 16);
}
public void buildGameWindow(int xSize, int ySize, int cellCount, String startMode) {
control.buildGameWindow(xSize, ySize, cellCount, startMode);
}
public void setCell(int mouseX, int mouseY, boolean value) {
control.setCell(mouseX, mouseY, value, offset);
}
public boolean isRunning() {
return control.isRunning();
}
public void setRunning(boolean state) {
control.setRunning(state);
}
public boolean isSliderLocked() {
return sliderLocked;
}
public void setSliderLocked(boolean sliderLocked) {
this.sliderLocked = sliderLocked;
}
public void nextGen() {
control.nextGen();
}
public boolean[][] getCells() {
return control.getCells();
}
public boolean isMouseLocked() {
return control.isMouseLocked();
}
public void setMouseLocked(boolean value) {
control.setMouseLocked(value);
}
public void clearGrid() {
control.clearGrid();
}
public void multipleGenSkip(int generations) {
control.multipleGenSkip(generations);
}
public int getGeneration() {
return control.getGeneration();
}
public int getVelocity() {
return control.getVelocity();
}
public void setVelocity(int velocity) {
control.setVelocity(velocity);
}
public void saveFirstGrid() {
control.saveFirstGrid();
}
public void previousGen() {
control.previousGen();
}
public void jump2Gen(int wantedtGen) {
control.jump2Gen(wantedtGen);
}
public void saveGridInDB(String gridName) {
control.saveGridInDB(gridName);
}
public List<String> getAllGrids() {
return control.getAllGrids();
}
public boolean checkName(String name) {
return control.checkName(name);
}
}
+22 -17
View File
@@ -1,13 +1,13 @@
package gui.windows;
import gui.control.GUI;
import gamecontrol.Control;
import gui.draw.DrawGrid;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GameWindow {
public class GameWindow extends GUI {
private final JFrame gameWindow;
private final DrawGrid drawGrid;
@@ -22,13 +22,14 @@ public class GameWindow {
private boolean mouseLeft = false, mouseRight = false;
public GameWindow(String title, GUI gui, int cellCountX, int cellCountY, int width, int height, int offset) {
public GameWindow(Control control, boolean manual, int cellCountX, int cellCountY, int width, int height) {
super(control);
this.cellCountX = cellCountX;
this.cellCountY = cellCountY;
this.title = title;
initPublicComponents();
gameWindow = new JFrame(title + " | Generation: " + gui.getGeneration());
gameWindow = new JFrame(title + " | Generation: " + getGeneration());
gameWindow.getContentPane().setPreferredSize(new Dimension(width + (2 * offset), height + (2 * offset)));
gameWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
@@ -36,19 +37,22 @@ public class GameWindow {
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) {
super.windowClosing(e);
if (gui.getControlWindow() != null){
gui.getControlWindow().dispose();
if (control.getControlWindow() != null){
control.getControlWindow().dispose();
}
gameWindow.dispose();
gui.setRunning(false);
gui.getMenuWindow().setVisibility(true);
gui.getMenuWindow().setFocus();
setRunning(false);
control.getMenuWindow().setVisibility(true);
control.getMenuWindow().setFocus();
}
});
@@ -61,10 +65,10 @@ public class GameWindow {
@Override
public void keyPressed(KeyEvent e) {
if (e.isControlDown() && e.isAltDown() && e.getKeyCode() == KeyEvent.VK_C) {
if (gui.getControlWindow() == null){
gui.buildControlWindow();
if (control.getControlWindow() == null){
control.buildControlWindow();
} else {
gui.setVisibility(true);
control.setVisibility(true);
}
}
@@ -81,9 +85,9 @@ public class GameWindow {
@Override
public void mouseDragged(MouseEvent e) {
if (mouseLeft) {
gui.setCell(e.getX(), e.getY(), true);
setCell(e.getX(), e.getY(), true);
} else if (mouseRight) {
gui.setCell(e.getX(), e.getY(), false);
setCell(e.getX(), e.getY(), false);
}
}
@@ -104,11 +108,11 @@ public class GameWindow {
switch (e.getButton()) {
case 1 -> {
mouseLeft = true;
gui.setCell(e.getX(), e.getY(), true);
setCell(e.getX(), e.getY(), true);
}
case 3 -> {
mouseRight = true;
gui.setCell(e.getX(), e.getY(), false);
setCell(e.getX(), e.getY(), false);
}
}
}
@@ -151,6 +155,7 @@ public class GameWindow {
gameWindow.setVisible(true);
}
public void showGrid(boolean[][] grid) {
if (drawGrid != null) {
drawGrid.showGrid(grid);
+21 -28
View File
@@ -1,9 +1,9 @@
package gui.windows;
import gui.control.GUI;
import gui.basics.Hover;
import gui.basics.RoundedBorder;
import gamecontrol.Control;
import gui.fundamental.Hover;
import gui.fundamental.RoundedBorder;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
@@ -13,15 +13,11 @@ import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.event.*;
public class MenuWindow {
public class MenuWindow extends GUI {
private GUI gui;
private final JFrame menuWindow;
private Font head;
private Font text;
private JLabel heading;
private final int xAxisMin = 6, xAxisMax = 2048;
@@ -51,13 +47,13 @@ public class MenuWindow {
private ImageIcon preview;
private JLabel previewLabel;
public MenuWindow(String title, GUI gui){
this.gui = gui;
public MenuWindow(Control control){
super(control);
initPublicComponents();
menuWindow = new JFrame();
menuWindow.setTitle(title);
menuWindow.setTitle(this.title);
ImageIcon imageIcon = new ImageIcon("src/assets/icons/Icon.png");
menuWindow.setIconImage(imageIcon.getImage());
@@ -83,10 +79,6 @@ public class MenuWindow {
private void initComponents() {
this.head = gui.getHead();
this.text = gui.getText();
initHeading();
initXAxis();
initYAxis();
@@ -114,7 +106,7 @@ public class MenuWindow {
xAxis.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if(!gui.isSliderLocked()) {
if(!isSliderLocked()) {
xAxisSize = xAxis.getValue();
updateSliderLabels(0, xAxisSize);
updateStartCells();
@@ -149,12 +141,12 @@ public class MenuWindow {
@Override
public void insertUpdate(DocumentEvent e) {
gui.setSliderLocked(true);
setSliderLocked(true);
String s = xAxisLabel.getText();
xAxis.setValue(Integer.parseInt(s));
xAxisSize = xAxis.getValue();
updateStartCells();
gui.setSliderLocked(false);
setSliderLocked(false);
}
@Override
@@ -178,7 +170,7 @@ public class MenuWindow {
yAxis.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if(!gui.isSliderLocked()) {
if(!isSliderLocked()) {
yAxisSize = yAxis.getValue();
updateSliderLabels(1, yAxisSize);
updateStartCells();
@@ -212,12 +204,12 @@ public class MenuWindow {
@Override
public void insertUpdate(DocumentEvent e) {
gui.setSliderLocked(true);
setSliderLocked(true);
String s = yAxisLabel.getText();
yAxis.setValue(Integer.parseInt(s));
yAxisSize = yAxis.getValue();
updateStartCells();
gui.setSliderLocked(false);
setSliderLocked(false);
}
@Override
@@ -241,7 +233,7 @@ public class MenuWindow {
startCells.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if(!gui.isSliderLocked()) {
if(!isSliderLocked()) {
cellCount = startCells.getValue();
updateSliderLabels(2, cellCount);
updateStartCells();
@@ -275,11 +267,11 @@ public class MenuWindow {
@Override
public void insertUpdate(DocumentEvent e) {
gui.setSliderLocked(true);
setSliderLocked(true);
String s = startCellsLabel.getText();
startCells.setValue(Integer.parseInt(s));
cellCount = startCells.getValue();
gui.setSliderLocked(false);
setSliderLocked(false);
}
@Override
@@ -303,8 +295,8 @@ public class MenuWindow {
addComboBoxEntry(modeBox, "Randomized");
addComboBoxEntry(modeBox, "Manuel");
for (int i = 0; i < gui.getAllGrids().size(); i++){
addComboBoxEntry(modeBox, gui.getAllGrids().get(i));
for (int i = 0; i < getAllGrids().size(); i++){
addComboBoxEntry(modeBox, getAllGrids().get(i));
}
modeName = new JLabel("Select Grid: ");
@@ -330,7 +322,7 @@ public class MenuWindow {
@Override
public void actionPerformed(ActionEvent e) {
gui.buildGameWindow(xAxisSize, yAxisSize, cellCount, modeBox.getSelectedItem().toString());
buildGameWindow(xAxisSize, yAxisSize, cellCount, modeBox.getSelectedItem().toString());
menuWindow.setVisible(false);
}
@@ -381,6 +373,7 @@ public class MenuWindow {
menuWindow.setVisible(visibility);
}
public void setFocus(){
menuWindow.requestFocus();
}
+6 -5
View File
@@ -2,6 +2,7 @@ package main;
import database.ReadDAO;
import gamecontrol.Control;
import java.util.Arrays;
import java.util.List;
@@ -29,12 +30,12 @@ public class Main {
public static void main(String[] args) {
// Control control = new Control();
// control.start();
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));
// ReadDAO readDAO = new ReadDAO();
// String[] x = readDAO.getGameInfo("test", new String[]{"MAX_CELLCOUNT", "GENERATION"});
// System.out.println(Arrays.toString(x));
}