diff --git a/Backup/v5/draw/Draw.java b/Backup/v5/draw/Draw.java index 9eb5d7f..88f3649 100644 --- a/Backup/v5/draw/Draw.java +++ b/Backup/v5/draw/Draw.java @@ -24,7 +24,7 @@ public class Draw extends JLabel { // for (int y = 0; y < Control.CELLCOUNT_Y; y++) { // if (Control.cells[x][y]) { // g.setColor(Color.BLACK); -// g.fillRect(x + GUI.XOFF, y + GUI.YOFF, 1, 1); +// g.fillRect(x + OldGUI.XOFF, y + OldGUI.YOFF, 1, 1); // } // } // } diff --git a/src/draw/Draw.java b/src/draw/Draw.java index a196229..ffd933f 100644 --- a/src/draw/Draw.java +++ b/src/draw/Draw.java @@ -5,6 +5,7 @@ import java.awt.*; public class Draw extends JPanel { private int xSize, ySize; + private int width, height; private float ratio; private Graphics2D g2d; @@ -12,9 +13,11 @@ public class Draw extends JPanel { private boolean drawLocked = false; - public Draw(int gridSizeX, int gridSizeY, float ratio) { + public Draw(int gridSizeX, int gridSizeY, int width, int height, float ratio) { this.xSize = gridSizeX; this.ySize = gridSizeY; + this.width = width; + this.height = height; this.ratio = ratio; currentGrid = new boolean[gridSizeX][gridSizeY]; @@ -36,8 +39,8 @@ public class Draw extends JPanel { super.paintComponent(g); g2d = (Graphics2D) g; - float cellSizeX = 800f / xSize; - float cellSizeY = 800f / ySize; + float cellSizeX = width / xSize; + float cellSizeY = height / ySize; if(ySize > xSize) { diff --git a/src/game/Clock.java b/src/game/Clock.java index a4fcf89..c0ba823 100644 --- a/src/game/Clock.java +++ b/src/game/Clock.java @@ -9,24 +9,20 @@ public class Clock extends Thread{ private boolean running = true; - public void start(Control control, GUI gui){ + public void start(Control control, GUI gui, int velocity){ Timer t = new Timer(); TimerTask tt = new TimerTask() { @Override public void run() { - if (running){ control.showGrid(control.getCells()); control.nextGen(); - - } } }; - - t.scheduleAtFixedRate(tt, 1000, 200); + t.scheduleAtFixedRate(tt, 1000, velocity); } diff --git a/src/game/Control.java b/src/game/Control.java index 84a13e3..eb4d5e2 100644 --- a/src/game/Control.java +++ b/src/game/Control.java @@ -2,6 +2,7 @@ package game; import gui.GUI; + import java.util.concurrent.ThreadLocalRandom; public class Control { @@ -21,13 +22,13 @@ public class Control { public void start() { gui = new GUI(this); - gui.controlWindow(); + gui.createMenuWindow(); } public void startGame() { clock = new Clock(); - clock.start(this, gui); + clock.start(this, gui, 2000); } public void buildGameWindow(int xSize, int ySize, int cellCount, StartMode startMode) { @@ -57,20 +58,20 @@ public class Control { gui = new GUI(this); } - if (startMode == StartMode.Manuel){ - gui.manuelGameWindow(this.xSize, this.ySize); - } else { - gui.gameWindow(this.xSize, this.ySize); - } + gui.createGameWindow(this.xSize, this.ySize); -// startGame(); + startGame(); } private void buildManuelGame() { - + for (int x = 0; x < xSize; x++) { + for (int y = 0; y < ySize; y++) { + cells[x][y] = false; + } + } } @@ -233,6 +234,10 @@ public class Control { showGrid(cells); } + + public void createControlWindow() { + gui.createControlWindow(); + } } diff --git a/src/gui/ControlWindow.java b/src/gui/ControlWindow.java new file mode 100644 index 0000000..f9d52bf --- /dev/null +++ b/src/gui/ControlWindow.java @@ -0,0 +1,15 @@ +package gui; + +import javax.swing.*; + +public class ControlWindow { + + private JFrame controlWindow; + + public ControlWindow(){ + controlWindow = new JFrame(); + controlWindow.setVisible(true); + controlWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); + } + +} diff --git a/src/gui/GUI.java b/src/gui/GUI.java index 994b139..f81fb64 100644 --- a/src/gui/GUI.java +++ b/src/gui/GUI.java @@ -1,457 +1,35 @@ package gui; -import draw.Draw; import game.Control; -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.*; - public class GUI { - private boolean sliderLocked = false; + private final String title = "Conway's game if Live"; private final Control control; - /* Universial Atributes */ - - private final String title = "Conway's Game of Life"; - - /* End of Universial Atributes */ - - /* Components of the menue View */ - private JFrame jfMenue; - - private JLabel heading; - private int xAxisSize = 6; - private JSlider xAxis; - private JLabel xAxisName; - private JTextField xAxisLabel; - private int yAxisSize = 6; - private JSlider yAxis; - private JLabel yAxisName; - private JLabel yAxisLabel; - private int cellCount = 6; - private JSlider startCells; - private JLabel startCellsName; - private JLabel startCellsLabel; - - private JLabel modeName; - private JComboBox modeBox; - - private MouseListener hover; - - private JButton startButton; - private JButton manuelStart; - - private ImageIcon preview; - private JLabel previewLabel; - - /* End of control view Elements */ - - /* Game view Elements */ - - private JFrame jfGame; - private Draw draw; - - private int xSize, ySize; - - /* End of Game view Elements */ - - private JFrame jfGameManuel; - - public GUI(Control control) { + private MenuWindow menuWindow; + private GameWindow gameWindow; + private ControlWindow controlWindow; + public GUI(Control control){ this.control = control; - } - public void controlWindow() { - jfMenue = new JFrame(); - - jfMenue.setTitle(title); - - ImageIcon imageIcon = new ImageIcon("src/data/PNG/Icon.png"); - jfMenue.setIconImage(imageIcon.getImage()); - - //getContentPane().setBackground(Color.decode("#121212")); - - jfMenue.setUndecorated(false); - - jfMenue.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - jfMenue.setAutoRequestFocus(false); - jfMenue.setLayout(null); - jfMenue.setSize(752, 424); - - jfMenue.setResizable(false); - - - initControlComponents(); - addControlComponents(); - - - jfMenue.setLocationRelativeTo(null); - jfMenue.setVisible(true); + public void createMenuWindow(){ + menuWindow = new MenuWindow(title, control); } - private void initControlComponents() { - - Font head = new Font("Segoe UI Light", Font.PLAIN, 24); - Font text = new Font("Segoe UI Light", Font.PLAIN, 16); - - heading = new JLabel("Control Panel"); - heading.setFont(head); - heading.setForeground(Color.decode("#121212")); - heading.setBounds(50, 25, 400, 50); - heading.setVisible(true); - - int xAxisMin = 6; - int xAxisMax = 1024; - xAxis = new JSlider(xAxisMin, xAxisMax); - xAxis.setBounds(180, 110, 200, 20); - xAxis.setFont(text); - xAxis.setForeground(Color.decode("#121212")); - xAxis.setValue(6); - xAxis.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - if(!sliderLocked) { - xAxisSize = xAxis.getValue(); - updateSliderLables(0, xAxisSize); - updateStartCells(); - } - } - }); - xAxis.setVisible(true); - - - - xAxisName = new JLabel("Breite in Zellen:"); - xAxisName.setBounds(50, 100, 200, 30); - xAxisName.setFont(text); - xAxisName.setForeground(Color.decode("#121212")); - xAxisName.setVisible(true); - - 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.addKeyListener(new KeyAdapter() { - public void keyTyped(KeyEvent evt) { - if (!Character.isDigit(evt.getKeyChar())) { - evt.consume(); - } - } - }); - - xAxisLabel.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) { - - sliderLocked = true; - String s = xAxisLabel.getText(); - xAxis.setValue(Integer.parseInt(s)); - sliderLocked = false; - } - - @Override - public void removeUpdate(DocumentEvent e) { - - } - - @Override - public void changedUpdate(DocumentEvent e) { - - } - }); - - - int yAxisMin = 6; - int yAxisMax = 1024; - yAxis = new JSlider(yAxisMin, yAxisMax); - yAxis.setBounds(180, 160, 200, 20); - yAxis.setFont(text); - yAxis.setForeground(Color.decode("#121212")); - yAxis.setValue(6); - yAxis.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - yAxisSize = yAxis.getValue(); - updateSliderLables(1, yAxisSize); - updateStartCells(); - } - }); - yAxis.setVisible(true); - - yAxisName = new JLabel("Höhe in Zellen:"); - yAxisName.setBounds(50, 150, 200, 30); - yAxisName.setFont(text); - yAxisName.setForeground(Color.decode("#121212")); - yAxisName.setVisible(true); - - yAxisLabel = new JLabel("6"); - yAxisLabel.setBounds(180, 130, 200, 30); - yAxisLabel.setFont(text); - yAxisLabel.setForeground(Color.decode("#121212")); - yAxisLabel.setVisible(true); - //TODO: Inputfield witch Changelistner to cange Slider - - startCells = new JSlider(6, 6); - startCells.setBounds(180, 210, 200, 20); - startCells.setFont(text); - startCells.setForeground(Color.decode("#121212")); - startCells.setValue(6); - startCells.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - cellCount = startCells.getValue(); - updateSliderLables(2, cellCount); - } - }); - startCells.setVisible(true); - - startCellsName = new JLabel("Start Zellen:"); - startCellsName.setBounds(50, 200, 200, 30); - startCellsName.setFont(text); - startCellsName.setForeground(Color.decode("#121212")); - startCellsName.setVisible(true); - - startCellsLabel = new JLabel("6"); - startCellsLabel.setBounds(180, 180, 200, 30); - startCellsLabel.setFont(text); - startCellsLabel.setForeground(Color.decode("#121212")); - startCellsLabel.setVisible(true); - - updateStartCells(); - - hover = new MouseAdapter() { - @Override - public void mouseEntered(MouseEvent e) { - super.mouseEntered(e); - JButton b = (JButton) e.getSource(); - b.setForeground(Color.decode("#C40233")); - b.setBounds(b.getX() - 10, b.getY() - 10, b.getWidth() + 20, b.getHeight() + 20); - } - - @Override - public void mouseExited(MouseEvent e) { - super.mouseExited(e); - JButton b = (JButton) e.getSource(); - b.setForeground(Color.decode("#121212")); - b.setBounds(b.getX() + 10, b.getY() + 10, b.getWidth() - 20, b.getHeight() - 20); - - } - }; - - modeName = new JLabel("Select Figure: "); - modeName.setBounds(50, 250, 200, 30); - modeName.setFont(text); - modeName.setForeground(Color.decode("#121212")); - modeName.setVisible(true); - - - modeBox = new JComboBox(); - modeBox.setBounds(180, 257, 100, 20); - addComboBoxEntry(modeBox, "Randomized"); - addComboBoxEntry(modeBox, "Task1"); - addComboBoxEntry(modeBox, "Blinker"); - addComboBoxEntry(modeBox, "Toad"); - - - startButton = new JButton(); - startButton.setText("Start Game"); - startButton.setFont(text); - startButton.setForeground(Color.decode("#121212")); - startButton.setBorderPainted(true); - startButton.setFocusPainted(false); - startButton.setContentAreaFilled(false); - startButton.setBounds(50, 310, 150, 50); - startButton.setVisible(true); - startButton.addMouseListener(hover); - startButton.setBorder(new RoundedBorder(25)); - startButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - - StartMode startMethod = StartMode.Task1; - - int index = modeBox.getSelectedIndex(); - - startMethod = StartMode.values()[index + 1]; // + 1 BECAUSE MANUEL HAS THE FIRST INDEX IN ENUM - - control.buildGameWindow(xAxisSize, yAxisSize, cellCount, startMethod); - } - }); - - manuelStart = new JButton(); - manuelStart.setText("Manuel Start"); - manuelStart.setFont(text); - manuelStart.setForeground(Color.decode("#121212")); - manuelStart.setBorderPainted(true); - manuelStart.setFocusPainted(false); - manuelStart.setContentAreaFilled(false); - manuelStart.setBounds(225, 310, 150, 50); - manuelStart.setVisible(true); - manuelStart.addMouseListener(hover); - manuelStart.setBorder(new RoundedBorder(25)); - manuelStart.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - control.buildGameWindow(xAxisSize, yAxisSize, cellCount, StartMode.Manuel); - } - }); - - - preview = new ImageIcon("src/data/PNG/Preview.png"); - previewLabel = new JLabel(preview); - previewLabel.setBounds(450, 45, 203, 302); - + public void createGameWindow(int cellCountX, int cellCountY){ + gameWindow = new GameWindow(title, control, cellCountX, cellCountY); } - private void updateStartCells() { - startCells.setMaximum(xAxisSize * yAxisSize); + public void createControlWindow(){ + controlWindow = new ControlWindow(); } - private void updateSliderLables(int slider, int val) { - switch (slider) { - case 0: - xAxisLabel.setText(String.valueOf(val)); - break; - case 1: - yAxisLabel.setText(String.valueOf(val)); - break; - case 2: - startCellsLabel.setText(String.valueOf(val)); - break; - } - } - - private void addControlComponents() { - jfMenue.add(heading); - jfMenue.add(xAxis); - jfMenue.add(xAxisName); - jfMenue.add(xAxisLabel); - jfMenue.add(yAxis); - jfMenue.add(yAxisName); - jfMenue.add(yAxisLabel); - jfMenue.add(startCells); - jfMenue.add(startCellsName); - jfMenue.add(startCellsLabel); - jfMenue.add(startButton); - jfMenue.add(manuelStart); - jfMenue.add(previewLabel); - jfMenue.add(modeName); - jfMenue.add(modeBox); - - } - - private void addComboBoxEntry(JComboBox comboBox, String entry) { - comboBox.addItem(entry); - } - - public void gameWindow(int xSize, int ySize) { - this.xSize = xSize; - this.ySize = ySize; - - - jfGame = new JFrame(title); - - 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, 800, 800); - - draw.setVisible(true); - - jfGame.add(draw); - - jfGame.pack(); - jfGame.setLayout(null); - jfGame.setLocationRelativeTo(null); - jfGame.setVisible(true); - - - } - - - public void manuelGameWindow(int xSize, int ySize) { - this.xSize = xSize; - this.ySize = ySize; - - - jfGameManuel = new JFrame(title); - - jfGameManuel.getContentPane().setPreferredSize(new Dimension(800, 800)); - - jfGameManuel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - jfGameManuel.setResizable(false); - - float ratio = (float)(ySize) / (float)(xSize); - draw = new Draw(this.xSize, this.ySize, ratio); - jfGameManuel.setBounds(0, 0, 800, 800); - - jfGameManuel.setVisible(true); - - - jfGameManuel.getContentPane().addMouseMotionListener(new MouseMotionListener() { - @Override - public void mouseDragged(MouseEvent e) { - - control.removeCell(e.getX(), e.getY()); - - - } - - @Override - public void mouseMoved(MouseEvent e) { - int top = jfGameManuel.getInsets().top; - System.out.println("top: " + top); - - control.addCell(e.getX(), e.getY()); - - } - }); - - jfGameManuel.add(draw); - - jfGameManuel.pack(); - jfGameManuel.setLayout(null); - jfGameManuel.setLocationRelativeTo(null); - jfGameManuel.setVisible(true); - - - } - - private void initGameComponents() { - } - - private void addGameComponents() { - } - - public void showGrid(boolean[][] grid) - { - if(draw != null) - { - draw.showGrid(grid); - } - else - { - System.err.println("There is no Window"); - } + public void showGrid(boolean[][] grid){ + gameWindow.showGrid(grid); } diff --git a/src/gui/GameWindow.java b/src/gui/GameWindow.java new file mode 100644 index 0000000..2c54760 --- /dev/null +++ b/src/gui/GameWindow.java @@ -0,0 +1,86 @@ +package gui; + +import draw.Draw; +import game.Control; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +public class GameWindow { + + private final JFrame jfGame; + private final Draw draw; + + private final int cellCountX; + private final int cellCountY; + + private int width, height; + private float ratio; + + public GameWindow(String title, Control control, int cellCountX, int cellCountY) { + this.cellCountX = cellCountX; + this.cellCountY = cellCountY; + + calcWindowSize(); + + jfGame = new JFrame(title); + + jfGame.getContentPane().setPreferredSize(new Dimension(width, height)); + jfGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + jfGame.addKeyListener(new KeyListener() { + @Override + public void keyTyped(KeyEvent e) { + + } + + @Override + public void keyPressed(KeyEvent e) { + if (e.isControlDown() && e.isAltDown() && e.getKeyCode() == KeyEvent.VK_C) { + control.createControlWindow(); + } + } + + @Override + public void keyReleased(KeyEvent e) { + + } + }); + + jfGame.setResizable(false); + + ratio = (float) (cellCountY) / (float) (cellCountX); + draw = new Draw(this.cellCountX, this.cellCountY, width, height, ratio); + draw.setBounds(0, 0, width, height); + + draw.setVisible(true); + + jfGame.add(draw); + + jfGame.pack(); + jfGame.setLayout(null); + jfGame.setLocationRelativeTo(null); + jfGame.setVisible(true); + } + + public void showGrid(boolean[][] grid) + { + if(draw != null) + { + draw.showGrid(grid); + } + else + { + System.err.println("you need to build the game gameWindow before showing a grid"); + } + } + + private void calcWindowSize(){ + + width = (int) (cellCountX * ratio ); + height = (int) (cellCountY * ratio); + + } +} diff --git a/src/gui/MenuWindow.java b/src/gui/MenuWindow.java new file mode 100644 index 0000000..143ec65 --- /dev/null +++ b/src/gui/MenuWindow.java @@ -0,0 +1,328 @@ +package gui; + +import game.Control; +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.*; + +public class MenuWindow { + + private final JFrame menuWindow; + + private JLabel heading; + private int xAxisSize = 6; + private JSlider xAxis; + private JLabel xAxisName; + private JTextField xAxisLabel; + private int yAxisSize = 6; + private JSlider yAxis; + private JLabel yAxisName; + private JLabel yAxisLabel; + private int cellCount = 6; + private JSlider startCells; + private JLabel startCellsName; + private JLabel startCellsLabel; + + private JLabel modeName; + private JComboBox modeBox; + + private MouseListener hover; + + private JButton startButton; + private JButton manuelStart; + + private ImageIcon preview; + private JLabel previewLabel; + + private boolean sliderLocked = false; + + public MenuWindow(String title, Control control){ + menuWindow = new JFrame(); + + menuWindow.setTitle(title); + + ImageIcon imageIcon = new ImageIcon("src/data/PNG/Icon.png"); + menuWindow.setIconImage(imageIcon.getImage()); + + + menuWindow.setUndecorated(false); + + menuWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + menuWindow.setAutoRequestFocus(false); + menuWindow.setLayout(null); + menuWindow.setSize(752, 424); + + menuWindow.setResizable(false); + + + initComponents(control); + addComponents(); + + + menuWindow.setLocationRelativeTo(null); + menuWindow.setVisible(true); + } + + private void initComponents(Control control) { + Font head = new Font("Segoe UI Light", Font.PLAIN, 24); + Font text = new Font("Segoe UI Light", Font.PLAIN, 16); + + heading = new JLabel("Control Panel"); + heading.setFont(head); + heading.setForeground(Color.decode("#121212")); + heading.setBounds(50, 25, 400, 50); + heading.setVisible(true); + + int xAxisMin = 6; + int xAxisMax = 1024; + xAxis = new JSlider(xAxisMin, xAxisMax); + xAxis.setBounds(180, 110, 200, 20); + xAxis.setFont(text); + xAxis.setForeground(Color.decode("#121212")); + xAxis.setValue(6); + xAxis.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + if(!sliderLocked) { + xAxisSize = xAxis.getValue(); + updateSliderLabels(0, xAxisSize); + updateStartCells(); + } + } + }); + xAxis.setVisible(true); + + + + xAxisName = new JLabel("Breite in Zellen:"); + xAxisName.setBounds(50, 100, 200, 30); + xAxisName.setFont(text); + xAxisName.setForeground(Color.decode("#121212")); + xAxisName.setVisible(true); + + 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.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent evt) { + if (!Character.isDigit(evt.getKeyChar())) { + evt.consume(); + } + } + }); + + xAxisLabel.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + + sliderLocked = true; + String s = xAxisLabel.getText(); + xAxis.setValue(Integer.parseInt(s)); + sliderLocked = false; + } + + @Override + public void removeUpdate(DocumentEvent e) { + + } + + @Override + public void changedUpdate(DocumentEvent e) { + + } + }); + + + int yAxisMin = 6; + int yAxisMax = 1024; + yAxis = new JSlider(yAxisMin, yAxisMax); + yAxis.setBounds(180, 160, 200, 20); + yAxis.setFont(text); + yAxis.setForeground(Color.decode("#121212")); + yAxis.setValue(6); + yAxis.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + yAxisSize = yAxis.getValue(); + updateSliderLabels(1, yAxisSize); + updateStartCells(); + } + }); + yAxis.setVisible(true); + + yAxisName = new JLabel("Höhe in Zellen:"); + yAxisName.setBounds(50, 150, 200, 30); + yAxisName.setFont(text); + yAxisName.setForeground(Color.decode("#121212")); + yAxisName.setVisible(true); + + yAxisLabel = new JLabel("6"); + yAxisLabel.setBounds(180, 130, 200, 30); + yAxisLabel.setFont(text); + yAxisLabel.setForeground(Color.decode("#121212")); + yAxisLabel.setVisible(true); + //TODO: Inputfield witch Changelistner to cange Slider + + startCells = new JSlider(6, 6); + startCells.setBounds(180, 210, 200, 20); + startCells.setFont(text); + startCells.setForeground(Color.decode("#121212")); + startCells.setValue(6); + startCells.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + cellCount = startCells.getValue(); + updateSliderLabels(2, cellCount); + } + }); + startCells.setVisible(true); + + startCellsName = new JLabel("Start Zellen:"); + startCellsName.setBounds(50, 200, 200, 30); + startCellsName.setFont(text); + startCellsName.setForeground(Color.decode("#121212")); + startCellsName.setVisible(true); + + startCellsLabel = new JLabel("6"); + startCellsLabel.setBounds(180, 180, 200, 30); + startCellsLabel.setFont(text); + startCellsLabel.setForeground(Color.decode("#121212")); + startCellsLabel.setVisible(true); + + updateStartCells(); + + hover = new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + super.mouseEntered(e); + JButton b = (JButton) e.getSource(); + b.setForeground(Color.decode("#C40233")); + b.setBounds(b.getX() - 10, b.getY() - 10, b.getWidth() + 20, b.getHeight() + 20); + } + + @Override + public void mouseExited(MouseEvent e) { + super.mouseExited(e); + JButton b = (JButton) e.getSource(); + b.setForeground(Color.decode("#121212")); + b.setBounds(b.getX() + 10, b.getY() + 10, b.getWidth() - 20, b.getHeight() - 20); + + } + }; + + modeName = new JLabel("Select Figure: "); + modeName.setBounds(50, 250, 200, 30); + modeName.setFont(text); + modeName.setForeground(Color.decode("#121212")); + modeName.setVisible(true); + + + modeBox = new JComboBox(); + modeBox.setBounds(180, 257, 100, 20); + addComboBoxEntry(modeBox, "Randomized"); + addComboBoxEntry(modeBox, "Task1"); + addComboBoxEntry(modeBox, "Blinker"); + addComboBoxEntry(modeBox, "Toad"); + + + startButton = new JButton(); + startButton.setText("Start Game"); + startButton.setFont(text); + startButton.setForeground(Color.decode("#121212")); + startButton.setBorderPainted(true); + startButton.setFocusPainted(false); + startButton.setContentAreaFilled(false); + startButton.setBounds(50, 310, 150, 50); + startButton.setVisible(true); + startButton.addMouseListener(hover); + startButton.setBorder(new RoundedBorder(25)); + startButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + StartMode startMethod = StartMode.Task1; + + int index = modeBox.getSelectedIndex(); + + startMethod = StartMode.values()[index + 1]; // + 1 BECAUSE MANUEL HAS THE FIRST INDEX IN ENUM + + control.buildGameWindow(xAxisSize, yAxisSize, cellCount, startMethod); + } + }); + + manuelStart = new JButton(); + manuelStart.setText("Manuel Start"); + manuelStart.setFont(text); + manuelStart.setForeground(Color.decode("#121212")); + manuelStart.setBorderPainted(true); + manuelStart.setFocusPainted(false); + manuelStart.setContentAreaFilled(false); + manuelStart.setBounds(225, 310, 150, 50); + manuelStart.setVisible(true); + manuelStart.addMouseListener(hover); + manuelStart.setBorder(new RoundedBorder(25)); + manuelStart.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + control.buildGameWindow(xAxisSize, yAxisSize, cellCount, StartMode.Manuel); + } + }); + + + preview = new ImageIcon("src/data/PNG/Preview.png"); + previewLabel = new JLabel(preview); + previewLabel.setBounds(450, 45, 203, 302); + + } + + private void updateStartCells() { + startCells.setMaximum(xAxisSize * yAxisSize); + } + + private void updateSliderLabels(int slider, int val) { + switch (slider) { + case 0: + xAxisLabel.setText(String.valueOf(val)); + break; + case 1: + yAxisLabel.setText(String.valueOf(val)); + break; + case 2: + startCellsLabel.setText(String.valueOf(val)); + break; + } + } + + private void addComponents(){ + menuWindow.add(heading); + menuWindow.add(xAxis); + menuWindow.add(xAxisName); + menuWindow.add(xAxisLabel); + menuWindow.add(yAxis); + menuWindow.add(yAxisName); + menuWindow.add(yAxisLabel); + menuWindow.add(startCells); + menuWindow.add(startCellsName); + menuWindow.add(startCellsLabel); + menuWindow.add(startButton); + menuWindow.add(manuelStart); + menuWindow.add(previewLabel); + menuWindow.add(modeName); + menuWindow.add(modeBox); + } + + private void addComboBoxEntry(JComboBox comboBox, String entry) { + comboBox.addItem(entry); + } + +}