Skip to content

Commit

Permalink
added maximum and minimum energy display
Browse files Browse the repository at this point in the history
  • Loading branch information
Shamus03 committed Apr 2, 2016
1 parent ce722a0 commit 4f8cb52
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/BallPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class BallPanel extends JPanel
private Vector gravity;
private BallPanelControlPanel controlPanel;

private double maxEnergy;
private double minEnergy;

public BallPanel(int width, int height)
{
super();
Expand All @@ -27,7 +30,8 @@ public BallPanel(int width, int height)
drawSystem = false;
sceneSelector = new SceneSelector(this);
gravity = new Vector(0, 0);

maxEnergy = Double.MIN_VALUE;
minEnergy = Double.MAX_VALUE;
setPreferredSize(new Dimension(width, height));

new Thread(new BallPanelDrawer()).start();
Expand Down Expand Up @@ -95,10 +99,21 @@ public void paintComponent(Graphics g)
system.draw(g);
}

double curEnergy = getTotalEnergy();
maxEnergy = Math.max(curEnergy, maxEnergy);
minEnergy = Math.min(curEnergy, minEnergy);

g.setColor(Color.BLACK);
g.setXORMode(Color.WHITE);
g.drawString("Total Energy: " + getTotalEnergy(),
g.drawString("Total Energy: " + curEnergy,
BORDER_WIDTH + 2, BORDER_WIDTH + 12);

g.drawString("Maximum Energy: " + maxEnergy,
BORDER_WIDTH + 2, BORDER_WIDTH + 25);

g.drawString("Minimum Energy: " + minEnergy,
BORDER_WIDTH + 2, BORDER_WIDTH + 38);

g.setPaintMode();
}

Expand Down

0 comments on commit 4f8cb52

Please sign in to comment.