Monday, 12 August 2013

Get coordinates from frame after button press

Get coordinates from frame after button press

Basically what I'd like to do is record the coordinates of a single mouse
click after a button is pressed for an ImageJ plugin. I've tried to do
this by syncing as follows:
int x; int y;
public int[] getPts(){
int[] xypts = new int[2];
synchronized(lock){
try{
lock.wait(3000);
}
catch(InterruptedException ie){};
}
xypts[0]= x;
xypts[1] = y;
return xypts;}
public void mouseClicked(MouseEvent e) {
x = e.getX();
y = e.getY();
x = canvas.offScreenX((int)x);
y = canvas.offScreenY((int)y);
IJ.log("Mouse pressed: "+x+","+y+modifiers(e.getModifiers()));
synchronized(lock){
lock.notifyAll();}
public void actionPerformed(ActionEvent evt){
Object source = evt.getSource();
int[] tempPts = new int[2];
tempPts = getPts();
}
The idea is that when a button (not shown) is pressed, then getPts is
called, which waits for a mouse event before continuing. Unfortunately,
when I do this, everything freezes until the timeout. However, if I call
getPts() in my main function (i.e. not triggered by an action) everything
works how I'd expect. Any ideas?
Thanks,
Matt

No comments:

Post a Comment