-
Notifications
You must be signed in to change notification settings - Fork 312
Expand file tree
/
Copy pathSnake.java
More file actions
45 lines (32 loc) · 927 Bytes
/
Snake.java
File metadata and controls
45 lines (32 loc) · 927 Bytes
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
39
40
41
42
43
44
45
package com.zetcode;
import java.awt.EventQueue;
import javax.swing.*;
public class Snake extends JFrame {
private static JFrame frame;
public Snake() {
initUI();
}
private void initUI() {
add(new Board());
setResizable(false);
pack();
setTitle("Snake");
setIconImage(new ImageIcon("src/resources/icon.png").getImage());
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//Basic method for restarting the game via disposing the current frame and initializing a new one.
public static void restartGame(){
frame.dispose();
startGame();
}
public static void main(String[] args) {
startGame();
}
private static void startGame(){
EventQueue.invokeLater(() -> {
frame = new Snake();
frame.setVisible(true);
});
}
}