Java Reference
In-Depth Information
canvas.addMouseListener (
new MouseAdapter () {
public void mouseClicked (MouseEvent e) {
if ((e.getModifiers () & InputEvent.BUTTON1 - MASK)! = 0)
saySomething ( " Left button pressed " ,e);
if ((e.getModifiers () & InputEvent.BUTTON2 - MASK)! = 0)
saySomething ( " Middle button pressed " ,e);
if ((e.getModifiers () & InputEvent.BUTTON3 - MASK)! = 0)
saySomething ( " Right button3 pressed " ,e);
if ((e.getModifiers () & InputEvent.ALT - MASK)! = 0)
saySomething ( " alt pressed " ,e);
if ((e.getModifiers () & InputEvent.META - MASK)! = 0)
saySomething ( " meta pressed " ,e);
} // mouseClicked
} // end anonymous class
); // end method call
} // ctor
/** Indicate what mouse event occurred. **/
void saySomething (String eventDescription, MouseEvent e) {
fTextArea.append (eventDescription + " on " +
e.getComponent ().getClass ().getName () + "\ n " );
}
} // class MouseButtonPanel
12.5 Popup menu
On all common graphical user interfaces a particular mouse button or combination
of a mouse button and key strokes (such as CTRL or ALT keys) brings up a popup
menu. A popup menu is a dialog window that appears close to the cursor and
that typically lists a set of operations related to what you clicked on (such as cut ,
copy , insert , paste in an editor).
To provide for platform portability, the AWT provides the isPopup-
Trigger() method in the MouseEvent class. This method returns a boolean
value to indicate if the standard button/key combination for a popup menu on a
particular platform was present during a mouse click event. You therefore don't
need to test for the buttons or button/keystroke combinations yourself and, more
importantly, you don't need to know and build in test code for all possible plat-
forms to detect a popup menu request.
 
Search WWH ::




Custom Search