forked from vvulevv/Snake-Java-Console-Game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidePanel.java
More file actions
64 lines (46 loc) · 1.6 KB
/
SidePanel.java
File metadata and controls
64 lines (46 loc) · 1.6 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JPanel;
public abstract class SidePanel extends JPanel implements Runnable {
private static final long serialVersionUID = 1L;
private static final Font LARGE_FONT = new Font("Tahoma", Font.BOLD, 20);
private static final Font MEDIUM_FONT = new Font("Tahoma", Font.BOLD, 16);
@SuppressWarnings("unused")
private static final Font SMALL_FONT = new Font("Tahoma", Font.BOLD, 12);
@SuppressWarnings("unused")
private Screen screen;
public SidePanel(Screen screen) {
this.screen = screen;
setPreferredSize(new Dimension(300, Screen.WIDTH * Screen.HEIGHT));
setBackground(Color.BLACK);
}
private static final int STATISTICS_OFFSET = 150;
private static final int CONTROLS_OFFSET = 320;
@SuppressWarnings("unused")
private static final int MESSAGE_STRIDE = 30;
private static final int SMALL_OFFSET = 30;
@SuppressWarnings("unused")
private static final int LARGE_OFFSET = 50;
@Override
public void paint(Graphics g) {
super.paintComponent(g);
/*
* Set the color to draw the font in to white.
*/
g.setColor(Color.WHITE);
/*
* Draw the game name onto the window.
*/
g.setFont(LARGE_FONT);
g.drawString("Snake Game", getWidth() / 2
- g.getFontMetrics().stringWidth("Snake Game") / 2, 50);
/*
* Draw the categories onto the window.
*/
g.setFont(MEDIUM_FONT);
g.drawString("Statistics", SMALL_OFFSET, STATISTICS_OFFSET);
g.drawString("Controls", SMALL_OFFSET, CONTROLS_OFFSET);
}
}