sho shi
sho shi

Reputation: 11

Get mouse coordinates using MouseListener with two classes

I need help with to get the x and y coorinates of my mouseclick. I have decribed place and named place dialogs who saves the information by the Plats-object which is another class. I need their coordinates depending on where you click on the panel. How can my class Plats get the x and y coordinates for the mouseclick? This is my superclass

    }
}

Upvotes: 1

Views: 83

Answers (1)

StanislavL
StanislavL

Reputation: 57381

Use SwingUtilities class. It has method

public static Point convertPoint(Component source,int x, int y,Component destination)

The source is the MouseEvent mev.getSource() destination is the target component.

Also you can use

public static void convertPointToScreen(Point p,Component c) 

if you need screen coordinates

Upvotes: 2

Related Questions