@@ -18,6 +18,9 @@ public class BallPanel extends JPanel
18
18
private Vector gravity ;
19
19
private BallPanelControlPanel controlPanel ;
20
20
21
+ private double maxEnergy ;
22
+ private double minEnergy ;
23
+
21
24
public BallPanel (int width , int height )
22
25
{
23
26
super ();
@@ -27,7 +30,8 @@ public BallPanel(int width, int height)
27
30
drawSystem = false ;
28
31
sceneSelector = new SceneSelector (this );
29
32
gravity = new Vector (0 , 0 );
30
-
33
+ maxEnergy = Double .MIN_VALUE ;
34
+ minEnergy = Double .MAX_VALUE ;
31
35
setPreferredSize (new Dimension (width , height ));
32
36
33
37
new Thread (new BallPanelDrawer ()).start ();
@@ -95,10 +99,21 @@ public void paintComponent(Graphics g)
95
99
system .draw (g );
96
100
}
97
101
102
+ double curEnergy = getTotalEnergy ();
103
+ maxEnergy = Math .max (curEnergy , maxEnergy );
104
+ minEnergy = Math .min (curEnergy , minEnergy );
105
+
98
106
g .setColor (Color .BLACK );
99
107
g .setXORMode (Color .WHITE );
100
- g .drawString ("Total Energy: " + getTotalEnergy () ,
108
+ g .drawString ("Total Energy: " + curEnergy ,
101
109
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
+
102
117
g .setPaintMode ();
103
118
}
104
119
0 commit comments