Skip to content

Commit 8f38c41

Browse files
committed
fix bug
1 parent 9569f65 commit 8f38c41

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/simulator/view/MainWindow.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void windowDeactivated(WindowEvent e) {
7373

7474
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
7575
pack();
76+
setLocationRelativeTo(null);
7677
setVisible(true);
7778
}
7879
}

src/simulator/view/Viewer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,14 @@ private void showHelp(Graphics2D g) {
217217
private void drawBodies(Graphics2D g) {
218218
for (Body b : _bodies) {
219219
if (isVisible(b)) {
220-
Vector2D pos = new Vector2D(_centerX, _centerY).plus(b.getPosition().scale(1.0 / _scale));
220+
Vector2D bodyDir = b.getPosition().scale(1.0 / _scale);
221+
Vector2D pos = new Vector2D(_centerX + bodyDir.getX(), _centerY - bodyDir.getY());
221222
g.setColor(_gColor.get(b.getgId()));
222223
g.fillOval((int) pos.getX() - 5, (int) pos.getY() - 5, 10, 10);
224+
g.setColor(Color.BLACK);
225+
g.drawString(b.getId(),
226+
(int) pos.getX() - g.getFontMetrics().stringWidth(b.getId()) / 2, // pos x
227+
(int) pos.getY() - 8);
223228

224229
if (_showVectors) {
225230
Vector2D force = pos.plus(b.getForce().direction().scale(30));

0 commit comments

Comments
 (0)