First Size Calculating

This commit is contained in:
Noah
2021-10-03 22:39:26 +02:00
parent e2c07d8d2e
commit 9cb505d4da
4 changed files with 46 additions and 20 deletions
+17 -1
View File
@@ -17,6 +17,8 @@ public class Control {
private int x = 0;
private int y = 0;
private int width, height;
public void start() {
@@ -57,7 +59,9 @@ public class Control {
gui = new GUI(this);
}
gui.createGameWindow(this.xSize, this.ySize);
calcSize();
gui.createGameWindow(this.xSize, this.ySize, this.width, this.height);
startGame();
@@ -243,6 +247,18 @@ public class Control {
gui.showGrid(cells);
}
private void calcSize(){
float c = 800;
width = Math.round(xSize * (c / xSize));
height = Math.round(ySize * (c / ySize));
System.out.println(xSize + " " + width);
System.out.println(ySize + " " + height);
}
private boolean checkCellCount() {
int counter = 0;
+11 -1
View File
@@ -1,15 +1,25 @@
package gui;
import javax.swing.*;
import java.awt.*;
public class ControlWindow {
private JFrame controlWindow;
public ControlWindow(){
controlWindow = new JFrame();
controlWindow.setVisible(true);
controlWindow.getContentPane().setPreferredSize(new Dimension(400, 800));
controlWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
controlWindow.setResizable(false);
// controlWindow.set
controlWindow.setLayout(null);
controlWindow.pack();
controlWindow.setVisible(true);
}
}
+2 -2
View File
@@ -20,8 +20,8 @@ public class GUI {
menuWindow = new MenuWindow(title, control);
}
public void createGameWindow(int cellCountX, int cellCountY){
gameWindow = new GameWindow(title, control, cellCountX, cellCountY);
public void createGameWindow(int cellCountX, int cellCountY, int width, int height){
gameWindow = new GameWindow(title, control, cellCountX, cellCountY, width, height);
}
public void createControlWindow(){
+16 -16
View File
@@ -9,7 +9,7 @@ import java.awt.event.*;
public class GameWindow {
private final JFrame jfGame;
private final JFrame gameWindow;
private final Draw draw;
private final int cellCountX;
@@ -20,17 +20,17 @@ public class GameWindow {
private boolean mouseLeft = false, mouseRight = false;
public GameWindow(String title, Control control, int cellCountX, int cellCountY) {
public GameWindow(String title, Control control, int cellCountX, int cellCountY, int width, int height) {
this.cellCountX = cellCountX;
this.cellCountY = cellCountY;
jfGame = new JFrame(title);
gameWindow = new JFrame(title);
jfGame.getContentPane().setPreferredSize(new Dimension(800, 800));
jfGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gameWindow.getContentPane().setPreferredSize(new Dimension(width, height));
gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jfGame.addKeyListener(new KeyListener() {
gameWindow.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
@@ -49,7 +49,7 @@ public class GameWindow {
}
});
jfGame.getContentPane().addMouseMotionListener(new MouseMotionListener() {
gameWindow.getContentPane().addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
@@ -66,7 +66,7 @@ public class GameWindow {
}
});
jfGame.getContentPane().addMouseListener(new MouseListener() {
gameWindow.getContentPane().addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -105,20 +105,20 @@ public class GameWindow {
}
});
jfGame.setResizable(false);
gameWindow.setResizable(false);
ratio = (float) (cellCountY) / (float) (cellCountX);
draw = new Draw(this.cellCountX, this.cellCountY, 800, 800, ratio);
draw.setBounds(0, 0, 800, 800);
draw = new Draw(this.cellCountX, this.cellCountY, width, height, ratio);
draw.setBounds(0, 0, width, height);
draw.setVisible(true);
jfGame.add(draw);
gameWindow.add(draw);
jfGame.pack();
jfGame.setLayout(null);
jfGame.setLocationRelativeTo(null);
jfGame.setVisible(true);
gameWindow.pack();
gameWindow.setLayout(null);
gameWindow.setLocationRelativeTo(null);
gameWindow.setVisible(true);
}
public void showGrid(boolean[][] grid) {