diff --git a/src/main/java/Snake/GameView.java b/src/main/java/Snake/GameView.java index 86594fb..6f72671 100644 --- a/src/main/java/Snake/GameView.java +++ b/src/main/java/Snake/GameView.java @@ -21,6 +21,8 @@ public class GameView extends JPanel this.gridSize = gridSize; } + public void addView(Drawable view) {views.add(view);} + public int getGridSize() { return gridSize; diff --git a/src/main/java/Snake/Window.java b/src/main/java/Snake/Window.java index 01166e2..21bb54f 100644 --- a/src/main/java/Snake/Window.java +++ b/src/main/java/Snake/Window.java @@ -1,8 +1,45 @@ package Snake; import javax.swing.*; +import java.awt.*; public class Window extends JFrame { + private GameView gameView; + + private final JButton startBtn; + + private final JButton pauseBtn; + + public Window(int viewSize, int gridSize) + { + super(); + setTitle("Snake"); + getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); + + gameView = new GameView(viewSize, gridSize); + startBtn = new JButton(); + pauseBtn = new JButton(); + startBtn.setText("Start Game!"); + pauseBtn.setText("Pause Game!"); + + final JPanel buttons = new JPanel(); + buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); + buttons.add(startBtn); + buttons.add(Box.createRigidArea(new Dimension(5, 0))); + buttons.add(pauseBtn); + + add(gameView); + add(Box.createVerticalStrut(10)); + add(buttons); + add(Box.createVerticalStrut(10)); + + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); + setResizable(false); + pack(); + setLocationRelativeTo(null); + setVisible(true); + } + }