-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.java
More file actions
49 lines (37 loc) · 1.35 KB
/
Display.java
File metadata and controls
49 lines (37 loc) · 1.35 KB
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
46
47
48
49
package pong;
import javax.swing.*;
import java.awt.*;
public class Display {
private JFrame frame;
private Canvas canvas;
private String title;
private int width, height;
public Display(String title, int width, int height) {
this.title = title;
this.width = width;
this.height = height;
createDisplay();
}
private void createDisplay() {
frame = new JFrame(title); //initializes JFrame
frame.setSize(width, height); //Sets size of JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Closes program as well as window
frame.setResizable(false); // Makes so you cant resize it
frame.setLocationRelativeTo(null); //Makes display pop up in center of screen
canvas = new Canvas();
canvas.setPreferredSize(new Dimension(width, height));
canvas.setMinimumSize(new Dimension(width, height));
canvas.setMinimumSize(new Dimension(width, height));
canvas.setFocusable(false); // Makes JFrame have focus not canvas
canvas.setBackground(Color.BLACK);
frame.add(canvas);
frame.pack();
frame.setVisible(true); //Shows JFrame
}
public Canvas getCanvas() {
return canvas;
}
public JFrame getFrame() {
return frame;
}
}