First Size Calculating
This commit is contained in:
+17
-1
@@ -17,6 +17,8 @@ public class Control {
|
|||||||
private int x = 0;
|
private int x = 0;
|
||||||
private int y = 0;
|
private int y = 0;
|
||||||
|
|
||||||
|
private int width, height;
|
||||||
|
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
|
|
||||||
@@ -57,7 +59,9 @@ public class Control {
|
|||||||
gui = new GUI(this);
|
gui = new GUI(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.createGameWindow(this.xSize, this.ySize);
|
calcSize();
|
||||||
|
|
||||||
|
gui.createGameWindow(this.xSize, this.ySize, this.width, this.height);
|
||||||
|
|
||||||
|
|
||||||
startGame();
|
startGame();
|
||||||
@@ -243,6 +247,18 @@ public class Control {
|
|||||||
gui.showGrid(cells);
|
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() {
|
private boolean checkCellCount() {
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|||||||
@@ -1,15 +1,25 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
public class ControlWindow {
|
public class ControlWindow {
|
||||||
|
|
||||||
private JFrame controlWindow;
|
private JFrame controlWindow;
|
||||||
|
|
||||||
public ControlWindow(){
|
public ControlWindow(){
|
||||||
|
|
||||||
controlWindow = new JFrame();
|
controlWindow = new JFrame();
|
||||||
controlWindow.setVisible(true);
|
|
||||||
|
controlWindow.getContentPane().setPreferredSize(new Dimension(400, 800));
|
||||||
controlWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
controlWindow.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||||
|
controlWindow.setResizable(false);
|
||||||
|
// controlWindow.set
|
||||||
|
controlWindow.setLayout(null);
|
||||||
|
|
||||||
|
controlWindow.pack();
|
||||||
|
controlWindow.setVisible(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -20,8 +20,8 @@ public class GUI {
|
|||||||
menuWindow = new MenuWindow(title, control);
|
menuWindow = new MenuWindow(title, control);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createGameWindow(int cellCountX, int cellCountY){
|
public void createGameWindow(int cellCountX, int cellCountY, int width, int height){
|
||||||
gameWindow = new GameWindow(title, control, cellCountX, cellCountY);
|
gameWindow = new GameWindow(title, control, cellCountX, cellCountY, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createControlWindow(){
|
public void createControlWindow(){
|
||||||
|
|||||||
+16
-16
@@ -9,7 +9,7 @@ import java.awt.event.*;
|
|||||||
|
|
||||||
public class GameWindow {
|
public class GameWindow {
|
||||||
|
|
||||||
private final JFrame jfGame;
|
private final JFrame gameWindow;
|
||||||
private final Draw draw;
|
private final Draw draw;
|
||||||
|
|
||||||
private final int cellCountX;
|
private final int cellCountX;
|
||||||
@@ -20,17 +20,17 @@ public class GameWindow {
|
|||||||
|
|
||||||
private boolean mouseLeft = false, mouseRight = false;
|
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.cellCountX = cellCountX;
|
||||||
this.cellCountY = cellCountY;
|
this.cellCountY = cellCountY;
|
||||||
|
|
||||||
|
|
||||||
jfGame = new JFrame(title);
|
gameWindow = new JFrame(title);
|
||||||
|
|
||||||
jfGame.getContentPane().setPreferredSize(new Dimension(800, 800));
|
gameWindow.getContentPane().setPreferredSize(new Dimension(width, height));
|
||||||
jfGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
gameWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
jfGame.addKeyListener(new KeyListener() {
|
gameWindow.addKeyListener(new KeyListener() {
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent e) {
|
public void keyTyped(KeyEvent e) {
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ public class GameWindow {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
jfGame.getContentPane().addMouseMotionListener(new MouseMotionListener() {
|
gameWindow.getContentPane().addMouseMotionListener(new MouseMotionListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e) {
|
||||||
@@ -66,7 +66,7 @@ public class GameWindow {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
jfGame.getContentPane().addMouseListener(new MouseListener() {
|
gameWindow.getContentPane().addMouseListener(new MouseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
|
||||||
@@ -105,20 +105,20 @@ public class GameWindow {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
jfGame.setResizable(false);
|
gameWindow.setResizable(false);
|
||||||
|
|
||||||
ratio = (float) (cellCountY) / (float) (cellCountX);
|
ratio = (float) (cellCountY) / (float) (cellCountX);
|
||||||
draw = new Draw(this.cellCountX, this.cellCountY, 800, 800, ratio);
|
draw = new Draw(this.cellCountX, this.cellCountY, width, height, ratio);
|
||||||
draw.setBounds(0, 0, 800, 800);
|
draw.setBounds(0, 0, width, height);
|
||||||
|
|
||||||
draw.setVisible(true);
|
draw.setVisible(true);
|
||||||
|
|
||||||
jfGame.add(draw);
|
gameWindow.add(draw);
|
||||||
|
|
||||||
jfGame.pack();
|
gameWindow.pack();
|
||||||
jfGame.setLayout(null);
|
gameWindow.setLayout(null);
|
||||||
jfGame.setLocationRelativeTo(null);
|
gameWindow.setLocationRelativeTo(null);
|
||||||
jfGame.setVisible(true);
|
gameWindow.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showGrid(boolean[][] grid) {
|
public void showGrid(boolean[][] grid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user