Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How get click position on JPanel?

4 views
Skip to first unread message

leonardo....@gmail.com

unread,
May 22, 2007, 4:42:14 PM5/22/07
to
How can I execute an action (or function) when the user will click
into the JPanel ???
Any examples may help-me...

tanks

Joe Attardi

unread,
May 22, 2007, 4:44:34 PM5/22/07
to
leonardo....@gmail.com wrote:
> How can I execute an action (or function) when the user will click
> into the JPanel ???
You need to make a class that implements MouseListener. There are a
bunch of different mouse events - I forget them all off the top of my
head - so see the Javadocs. But a MouseListener is what you want. Or if
a click is all you're interested in, extend MouseAdapter.

Hope this helps..

Joe

cyprian

unread,
May 25, 2007, 5:20:03 AM5/25/07
to
On May 22, 9:44 pm, Joe Attardi <jatta...@gmail.com> wrote:

The getLocationOnScreen() method of the MouseEvent class that returns
a Point object is what you need. It gives the x,y coordinates,
absolute coordinates, of mouse event. If you want a position relative
to the container itself, that is the JPanel, then you might be
thinking of getMousePosition() of the component class that returns a
point relative to the position of the component.
I believe you know how to extend the mouseadapter or implement the
various mouselisteners.

0 new messages