Allan Bruce
2003-12-18 14:36:10 UTC
I want to be able to detect when a mouse button is clicked in my JPanel.
The code below seems to only work for the forw where no components are. How
do I change this so that I can get the events for the JPanel? Also, is
there a way to determine at what co-ordinates the JPanel is at, i.e. the
upper-left and the lower-right ?
Thanks
Allan
// in constructor
addMouseListener(this);
// elsewhere
public void mouseClicked(MouseEvent e)
{
if (e.getButton() == e.BUTTON1) // left mouse click
{
System.out.print("Left ");
}
else
capturing = false;
System.out.print("Button Clicked\n");
}
The code below seems to only work for the forw where no components are. How
do I change this so that I can get the events for the JPanel? Also, is
there a way to determine at what co-ordinates the JPanel is at, i.e. the
upper-left and the lower-right ?
Thanks
Allan
// in constructor
addMouseListener(this);
// elsewhere
public void mouseClicked(MouseEvent e)
{
if (e.getButton() == e.BUTTON1) // left mouse click
{
System.out.print("Left ");
}
else
capturing = false;
System.out.print("Button Clicked\n");
}