I have a square that I want to be able to drag into another square, then test if it's
really inside or not. I want to use three different methods triggered by MOUSE_PRESSED,
MOUSE_DRAGGED, and MOUSE_RELEASED. I can't figure out how to find out which event is
happening to my square. (using java.awt.event.MouseEvent). Can anyone help? Please respond
via email.
Many thanks,
Jeff
Jeff Bull
jeff.bull@ilsinc.com
Since I take it that these squares are components, you will have to use -contains- function to see whether or not these
mouse events are inside the square. If the contains funcion returns true, all the mouse events will work, relating to this
square. Once totally in the other square, simply do a check of it's dimensions and position relative to the target square's
dimensions and position. I hope this answers your question. I'll send this to you as well.
Shari
Shari
Here goes ...
One possible implementation is:
class Frame
{
.
.
.
SquareEventListener sel =
new SquareEventListener(this);
.
.
.
componentSquare.addMouseListener(sel);
.
.
.
}
class myApp extends Applet
{
.
.
.
}
class SquareEventListener extends MouseAdapter
{
public SquareEventListener
(
InFrame f
)
{
this.f = f;
myApp tempApp = f.getApplet();
}
MyFrame = f;
public void mousePressed
(
MouseEvent me1
}
{
.
.
.
// doing something useful here
.
.
.
}
public void mouseDragged
(
MouseEvent me1
)
{
.
.
.
// doing something useful here
.
.
.
}
public void mouseReleased
(
MouseEvent me1
)
{
.
.
.
// doing something useful here
.
.
.
}
end of code
if you need more info, consult texts which explain the MouseAdapter class
hope this helped (if it didn't it would've been a waste of my time .... :-)~
Mike
mdsgt@yahoo.com