Java Reference
In-Depth Information
bt = new JButton ( " NorthEast Resize " );
bt.setCursor (new Cursor (Cursor.NE - RESIZE - CURSOR));
add (bt);
bt = new JButton ( " NorthWest Resize " );
bt.setCursor (new Cursor (Cursor.NW - RESIZE - CURSOR));
add (bt);
bt = new JButton ( " SouthWest Resize " );
bt.setCursor (new Cursor (Cursor.SW - RESIZE - CURSOR));
add (bt);
bt = new JButton ( " SouthEast Resize " );
bt.setCursor (new Cursor (Cursor.SE - RESIZE - CURSOR));
add (bt);
} // ctor
} // class CursorPanel
With Java 1.2 came the capability to create your own custom cursor icons. The
method
Cursor createCustomCursor (Image cursor, Point hotSpot,
String name)
in the java.awt.Toolkit class includes an image for the cursor in the param-
eter list. The second parameter specifies the so-called hotspot that sets the pixel's
(x, y) coordinates relative to the top-left corner of the image where the click
occurs. (For example, the hotspot would specify the tip of an arrow cursor.) The
last parameter provides the name of the cursor for the Java Accessibility system
to use. (The Accessibility framework, not discussed here, provides enhancements
to the GUI to assist handicapped users.)
12.4 Mouse buttons
In Chapter 7 we discussed mouse events that are produced by actions such as
clicking on the primary mouse button. This is usually the left button for a two- or
three-button mouse. You can detect clicks on the right mouse button, or its equiv-
alent, on either a one-, two- or three-button mouse with the getModifiers()
method of the MouseEvent class (inherited from the Event class). This code
snippet illustrates the technique:
public void mouseClicked (MouseEvent e) {
if (g.getModifiers () & InputEvent.BUTTON3 - MASK)! = 0)
doSomething ();
...
 
Search WWH ::




Custom Search