-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWindow.java
38 lines (26 loc) · 977 Bytes
/
Window.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Window extends Canvas{
public JFrame frame;
//Constructor
public Window(int w, int h, String title, Game game) {
frame = new JFrame(title); //Creates the JFrame window
//Sets dimensions
game.setPreferredSize(new Dimension(w,h));
frame.setSize(new Dimension(w,h));
frame.setMaximumSize(new Dimension(w,h));
frame.setMinimumSize(new Dimension(w,h));
//Settings
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
//Adds the game object
frame.add(game);
//Adjust screen size to fit the game
frame.pack();
frame.setVisible(true);
//Starts the thread after the Window has been created
game.start();
}
}