Control Window Update. Control Window may need a Recontruction.
This commit is contained in:
+15
-4
@@ -1,5 +1,6 @@
|
||||
package game;
|
||||
|
||||
import gui.ControlWindow;
|
||||
import gui.GUI;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@@ -51,18 +52,20 @@ public class Control {
|
||||
}
|
||||
case Manuel -> {
|
||||
buildManuelGame();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (gui == null) {
|
||||
gui = new GUI(this);
|
||||
}
|
||||
|
||||
calcSize();
|
||||
|
||||
gui.createGameWindow(this.xSize, this.ySize, this.width, this.height);
|
||||
|
||||
if (startMode == StartMode.Manuel){
|
||||
buildControlWindow();
|
||||
}
|
||||
|
||||
|
||||
startGame();
|
||||
|
||||
@@ -219,10 +222,18 @@ public class Control {
|
||||
}
|
||||
|
||||
|
||||
public void createControlWindow() {
|
||||
public void buildControlWindow() {
|
||||
gui.createControlWindow();
|
||||
}
|
||||
|
||||
public ControlWindow getControlWindow(){
|
||||
return gui.getControlWindow();
|
||||
}
|
||||
|
||||
public void setVisibility(boolean value){
|
||||
gui.setVisibility(value);
|
||||
}
|
||||
|
||||
public void setCell(int mouseX, int mouseY, boolean value) {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
@@ -7,14 +7,16 @@ public class ControlWindow {
|
||||
|
||||
private JFrame controlWindow;
|
||||
|
||||
public ControlWindow(){
|
||||
private final int width = 400, height = 800;
|
||||
|
||||
public ControlWindow(GameWindow gameWindow, int offset){
|
||||
|
||||
controlWindow = new JFrame();
|
||||
|
||||
controlWindow.getContentPane().setPreferredSize(new Dimension(400, 800));
|
||||
controlWindow.getContentPane().setPreferredSize(new Dimension(width, height));
|
||||
controlWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
controlWindow.setResizable(false);
|
||||
// controlWindow.set
|
||||
controlWindow.setLocation(gameWindow.getPos().x - (width + offset), gameWindow.getPos().y);
|
||||
controlWindow.setLayout(null);
|
||||
|
||||
controlWindow.pack();
|
||||
@@ -22,4 +24,8 @@ public class ControlWindow {
|
||||
|
||||
}
|
||||
|
||||
public void setVisibility(boolean value){
|
||||
controlWindow.setVisible(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-1
@@ -2,10 +2,15 @@ package gui;
|
||||
|
||||
import game.Control;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class GUI {
|
||||
|
||||
private final String title = "Conway's game if Live";
|
||||
|
||||
private final int offset = 10;
|
||||
|
||||
private final Control control;
|
||||
|
||||
private MenuWindow menuWindow;
|
||||
@@ -20,17 +25,25 @@ public class GUI {
|
||||
menuWindow = new MenuWindow(title, control);
|
||||
}
|
||||
|
||||
|
||||
public void createGameWindow(int cellCountX, int cellCountY, int width, int height){
|
||||
gameWindow = new GameWindow(title, control, cellCountX, cellCountY, width, height);
|
||||
}
|
||||
|
||||
public void createControlWindow(){
|
||||
controlWindow = new ControlWindow();
|
||||
controlWindow = new ControlWindow(gameWindow, offset);
|
||||
}
|
||||
|
||||
public void showGrid(boolean[][] grid){
|
||||
gameWindow.showGrid(grid);
|
||||
}
|
||||
|
||||
public void setVisibility(boolean value){
|
||||
controlWindow.setVisibility(value);
|
||||
}
|
||||
|
||||
public ControlWindow getControlWindow() {
|
||||
return controlWindow;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-1
@@ -39,7 +39,12 @@ public class GameWindow {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.isControlDown() && e.isAltDown() && e.getKeyCode() == KeyEvent.VK_C) {
|
||||
control.createControlWindow();
|
||||
if (control.getControlWindow() == null){
|
||||
control.buildControlWindow();
|
||||
} else {
|
||||
control.setVisibility(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +134,10 @@ public class GameWindow {
|
||||
}
|
||||
}
|
||||
|
||||
public Point getPos(){
|
||||
return gameWindow.getLocation();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user