Java Reference
In-Depth Information
Java's designers chose confusing names here, because the
setIconImage
method
doesn't accept an
ImageIcon
as its parameter.
A screenshot of the button's appearance when it is placed into a frame follows.
Notice that a smaller version of the icon also appears in the top-left corner of the
window, because of the
setIconImage
call:
So far, we've worked exclusively with
ActionListener
objects. When we want to
listen to mouse clicks or movements, we use another type of listener called a
MouseInputListener
. The
MouseInputListener
interface resides in the
javax.swing.event
package, which you'll need to import:
import javax.swing.event.*; // for mouse events
The
MouseInputListener
interface methods for handling mouse input are listed
in Table 14.7. There are quite a few methods, and you probably won't want to imple-
ment them all. Many programs handle only button presses or cursor movements. In
these cases, you have to write empty versions of all the other
MouseInputListener
methods, because otherwise the class doesn't implement the interface properly and
won't compile.
Table 14.7
The Methods of the
MouseInputListener
Interface
public void mouseClicked(MouseEvent event)
Invoked when the mouse button has been clicked (pressed and released) on a component.
public void mouseDragged(MouseEvent event)
Invoked when a mouse button is pressed on a component and then dragged.
public void mouseEntered(MouseEvent event)
Invoked when the mouse enters a component.
public void mouseExited(MouseEvent event)
Invoked when the mouse exits a component.
public void mouseMoved(MouseEvent event)
Invoked when the mouse has been moved onto a component but no buttons have been pushed.
public void mousePressed(MouseEvent event)
Invoked when a mouse button has been pressed on a component.
public void mouseReleased(MouseEvent event)
Invoked when a mouse button has been released on a component.
Search WWH ::
Custom Search