From c23792cb80f2f0f1f19cb3f15deb98e8be72c486 Mon Sep 17 00:00:00 2001 From: astei Date: Mon, 19 Apr 2010 20:52:15 +0000 Subject: [PATCH] Add position counter fixing #11 git-svn-id: https://desert.svn.sourceforge.net/svnroot/desert@66 cbff3641-ea5c-438d-a1bd-c9f42921e016 --- src/org/sourceforge/desert/DesertPanel.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/org/sourceforge/desert/DesertPanel.java b/src/org/sourceforge/desert/DesertPanel.java index b156314..a72a3e7 100644 --- a/src/org/sourceforge/desert/DesertPanel.java +++ b/src/org/sourceforge/desert/DesertPanel.java @@ -34,6 +34,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseEvent; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.Box; @@ -55,17 +57,19 @@ public class DesertPanel extends Panel { this.timer = new Timer(FRAMERATE); this.drawingBoard = new DrawingBoard(); + final XYMouseListener xyMouse = new XYMouseListener(); final FramerateLabel framerateLabel = new FramerateLabel(); final ParticleCountLabel particleCountLabel = this.new ParticleCountLabel(); this.add(this.getDrawingBoard(), BorderLayout.CENTER); this.add(verticalBox( - horizontalBox(framerateLabel, particleCountLabel), + horizontalBox(framerateLabel, particleCountLabel, xyMouse), horizontalBox(new Label("Particle engine: "), this.new ParticleEngineChoice()), horizontalBox(new Label("Particle type: "), this.new ParticleTypeChoice()) ), BorderLayout.SOUTH); this.getTimer().addActionListener(this.getDrawingBoard()); + this.getDrawingBoard().addMouseMotionListener(xyMouse); this.getTimer().addActionListener(framerateLabel); this.getTimer().addActionListener(particleCountLabel); this.gcThread = new GCThread(); @@ -191,6 +195,22 @@ public class DesertPanel extends Panel { } + /** + * + * @author codistmonk (creation 2010-04-15) + */ + private static final class XYMouseListener extends Label implements MouseMotionListener { + + @Override + public final void mouseMoved(final MouseEvent event) { + this.setText("(" + event.getX() + "," + event.getY() + ")"); + } + + @Override + public final void mouseDragged(final MouseEvent event) {} + + } + public static final int FRAMERATE = 25; /** -- 2.11.4.GIT