-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataPanel.java
56 lines (44 loc) · 1.38 KB
/
DataPanel.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
46
47
48
49
50
51
52
53
54
55
56
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JPanel;
// TimePanel displays the simulation time
@SuppressWarnings("serial")
public class DataPanel extends JPanel{
private int width = 200, height = 50;
private double time = 0;
private Simulation sim;
private JLabel timeLabel;
private JLabel bodiesLabel;
private JLabel pausedLabel;
// constructor initializes time panel and label components
public DataPanel(Simulation s) {
this.setSize(new Dimension(width, height));
this.setOpaque(false);
timeLabel = new JLabel("Simulation time: " + s.iterations *s.dt + " s");
timeLabel.setForeground(Color.white);
this.add(timeLabel);
bodiesLabel = new JLabel("Bodies: " + s.bodies.size);
bodiesLabel.setForeground(Color.white);
this.add(bodiesLabel);
// only shown when simulation is paused (not by default)
pausedLabel = new JLabel("Simulation Paused");
pausedLabel.setForeground(Color.white);
}
// updates time label (called from Space)
public void updateTime(double t) {
time = t;
timeLabel.setText("Simulation time: " + Math.round(time*10.0)/10.0 + " s");
}
// toggles pausedLabel visibility (called from AppFrame)
public void togglePaused(boolean simRunning) {
if(!simRunning) {
this.add(pausedLabel);
simRunning = false;
}
else {
this.remove(pausedLabel);
simRunning = true;
}
}
}