Skip to content

Commit 4f8cb52

Browse files
committed
added maximum and minimum energy display
1 parent ce722a0 commit 4f8cb52

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/BallPanel.java

+17-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class BallPanel extends JPanel
1818
private Vector gravity;
1919
private BallPanelControlPanel controlPanel;
2020

21+
private double maxEnergy;
22+
private double minEnergy;
23+
2124
public BallPanel(int width, int height)
2225
{
2326
super();
@@ -27,7 +30,8 @@ public BallPanel(int width, int height)
2730
drawSystem = false;
2831
sceneSelector = new SceneSelector(this);
2932
gravity = new Vector(0, 0);
30-
33+
maxEnergy = Double.MIN_VALUE;
34+
minEnergy = Double.MAX_VALUE;
3135
setPreferredSize(new Dimension(width, height));
3236

3337
new Thread(new BallPanelDrawer()).start();
@@ -95,10 +99,21 @@ public void paintComponent(Graphics g)
9599
system.draw(g);
96100
}
97101

102+
double curEnergy = getTotalEnergy();
103+
maxEnergy = Math.max(curEnergy, maxEnergy);
104+
minEnergy = Math.min(curEnergy, minEnergy);
105+
98106
g.setColor(Color.BLACK);
99107
g.setXORMode(Color.WHITE);
100-
g.drawString("Total Energy: " + getTotalEnergy(),
108+
g.drawString("Total Energy: " + curEnergy,
101109
BORDER_WIDTH + 2, BORDER_WIDTH + 12);
110+
111+
g.drawString("Maximum Energy: " + maxEnergy,
112+
BORDER_WIDTH + 2, BORDER_WIDTH + 25);
113+
114+
g.drawString("Minimum Energy: " + minEnergy,
115+
BORDER_WIDTH + 2, BORDER_WIDTH + 38);
116+
102117
g.setPaintMode();
103118
}
104119

0 commit comments

Comments
 (0)