-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfoPanel.java
More file actions
97 lines (79 loc) · 2.83 KB
/
InfoPanel.java
File metadata and controls
97 lines (79 loc) · 2.83 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.awt.*;
import javax.swing.*;
/**
* Information display panel showing FPS, player coordinates,
* active effects, and collectibles count.
*/
public class InfoPanel extends JPanel {
private JLabel fpsLabel;
private JLabel positionLabel;
private JLabel effectsLabel;
private JLabel collectiblesLabel;
private JTextField fpsTF;
private JTextField positionTF;
private JTextField effectsTF;
private JTextField collectiblesTF;
public InfoPanel() {
setLayout(new GridLayout(2, 4));
setPreferredSize(new Dimension(800, 60));
setBackground(Color.DARK_GRAY);
// Create labels
fpsLabel = new JLabel("FPS:");
positionLabel = new JLabel("Position:");
effectsLabel = new JLabel("Effect:");
collectiblesLabel = new JLabel("Collectibles:");
fpsLabel.setForeground(Color.WHITE);
positionLabel.setForeground(Color.WHITE);
effectsLabel.setForeground(Color.WHITE);
collectiblesLabel.setForeground(Color.WHITE);
// Create text fields
fpsTF = new JTextField(5);
positionTF = new JTextField(10);
effectsTF = new JTextField(10);
collectiblesTF = new JTextField(10);
fpsTF.setForeground(Color.BLACK);
positionTF.setForeground(Color.BLACK);
effectsTF.setForeground(Color.BLACK);
collectiblesTF.setForeground(Color.BLACK);
// Make text fields non-editable
fpsTF.setEditable(false);
positionTF.setEditable(false);
effectsTF.setEditable(false);
collectiblesTF.setEditable(false);
// Set colors
fpsTF.setBackground(Color.CYAN);
positionTF.setBackground(Color.YELLOW);
effectsTF.setBackground(Color.GREEN);
collectiblesTF.setBackground(Color.ORANGE);
// Add to panel
add(fpsLabel);
add(fpsTF);
add(positionLabel);
add(positionTF);
add(effectsLabel);
add(effectsTF);
add(collectiblesLabel);
add(collectiblesTF);
// Initialize values
fpsTF.setText("0");
positionTF.setText("(0, 0)");
effectsTF.setText("None");
collectiblesTF.setText("0 / 0");
}
public void updateFPS(int fps) {
fpsTF.setText(String.valueOf(fps));
}
public void updatePlayerPosition(int worldX, int worldY) {
positionTF.setText("(" + worldX + ", " + worldY + ")");
}
public void updateActiveEffects(String effectName) {
if (effectName == null || effectName.isEmpty()) {
effectsTF.setText("None");
} else {
effectsTF.setText(effectName);
}
}
public void updateCollectibles(int collected, int total) {
collectiblesTF.setText(collected + " / " + total);
}
}