views:

19

answers:

1

In my project,I will get the coordinates of some points from an XML file,and create some visual components using this information ? I am planning to give these components to a Java swing frame or panel. However,The users are supposed to click on the figure(which I will construct using Graphics 2d libraries) and select two points and give a label to the points between those two points ? How can i get the clicks clicked on JFrame or JPanel(i.e events for this kind of actions) ?

+3  A: 

A MouseAdapter is what you want, add one to the JPanel you're drawing: http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/MouseAdapter.html

Tom