[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: guidance
> in my Frame i want to detect that the mouse has been moved over a
> button. ( i am programming in java ) how can this be acheived ?
Hi, there are (atleast) two ways to do this:
#1: Use a MouseMotionListener or Adapter
button.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent evt) {
//... do what you want with mosue movements...
}
}
);
You can use a separate class that implements MouseMotionListener too.
(Here ive used an anonymous inner class)
#2: Subclass Button and enableEvents(AWTEvent.MOUSE_EVENT) in its
constructor after calling super().
Then add a method for processing the mouse event:
public void processMouseEvent( Mouse Event e) {
...
}
As for your other Question...
>
> i have an object 'a'( say a frame ) and in it another object 'b' ( say
> a
> button ). now 'a' can be the actionlistener of 'b'. is it possible that 'b'
> can be its own actionlistener ? 'b' is a button.
Yes It's possible... you can use addActionListener(this) provided that
class implements the ActionListener interface.
Hope this helps,
Rohit