-
Notifications
You must be signed in to change notification settings - Fork 0
/
Display.java
46 lines (37 loc) · 1.03 KB
/
Display.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
39
40
41
42
43
44
45
//this is window for playing snake game
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Display {
private String title;
private int width;
private int height;
private JFrame frame;
private Canvas canvas;
public Display(String title,int width,int height){
this.title = title;
this.width = width;
this.height = height;
createDisplay();
}
//this is to create display of snake game
public void createDisplay(){
frame = new JFrame(title);
frame.setVisible(true);
frame.setSize(width,height);
frame.setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
canvas = new Canvas();
canvas.setPreferredSize(new Dimension(width,height));
canvas.setFocusable(false);
frame.add(canvas);
}
public Canvas getCanvas(){
return canvas;
}
public JFrame getFrame(){
return frame;
}
}