Browse Source

update

main
Justin Senn 2 years ago
parent
commit
81c7825b6f
  1. 2
      src/main/java/Snake/GameView.java
  2. 37
      src/main/java/Snake/Window.java

2
src/main/java/Snake/GameView.java

@ -21,6 +21,8 @@ public class GameView extends JPanel
this.gridSize = gridSize; this.gridSize = gridSize;
} }
public void addView(Drawable view) {views.add(view);}
public int getGridSize() public int getGridSize()
{ {
return gridSize; return gridSize;

37
src/main/java/Snake/Window.java

@ -1,8 +1,45 @@
package Snake; package Snake;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
public class Window extends JFrame 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);
}
} }
Loading…
Cancel
Save