Hello!
I´m working with images. My program displays an image in a ScrollingImagePanel, I want to click the image and get the x,y coordinates. I try to do this adding a Mouse listener but I didn´t obtain good results. If I add the same listener to another component it works fine. What am I doing wrong? Here is part of my code:
panel1i=new ScrollingImagePanel(imagen,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
panel1i.addMouseListener( new MouseClickHandler() );
panel0.add(BotonEntrena);
panel2.add(panel1i);
c.add(panel2,BorderLayout.CENTER);
// inner class to handle mouse events
private class MouseClickHandler extends MouseAdapter {
public void mouseClicked( MouseEvent e )
{
xPos = e.getX();
yPos = e.getY();
String s =
"x = " + xPos + " y = " + yPos;
System.out.println("x = " + xPos + " y = " + yPos);
setTitle( s ); // set the title bar of the window
}
}
I´m working with images. My program displays an image in a ScrollingImagePanel, I want to click the image and get the x,y coordinates. I try to do this adding a Mouse listener but I didn´t obtain good results. If I add the same listener to another component it works fine. What am I doing wrong? Here is part of my code:
panel1i=new ScrollingImagePanel(imagen,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
panel1i.addMouseListener( new MouseClickHandler() );
panel0.add(BotonEntrena);
panel2.add(panel1i);
c.add(panel2,BorderLayout.CENTER);
// inner class to handle mouse events
private class MouseClickHandler extends MouseAdapter {
public void mouseClicked( MouseEvent e )
{
xPos = e.getX();
yPos = e.getY();
String s =
"x = " + xPos + " y = " + yPos;
System.out.println("x = " + xPos + " y = " + yPos);
setTitle( s ); // set the title bar of the window
}
}