| MouseEvent |
|
typedict |
| |
A
MouseEvent
indicates that the mouse was moved, or a that mouse button was
pressed, released, or clicked.
Two new fields, namely
button
and
modifiersdown,
provide better access to information stored in a
MouseEvent
than is available using the
modifiers
field, so applications that handle
MouseEvents
should seriously consider using the new fields.
The fields in a
MouseEvent
are:
| button |
An
int
that identifies the mouse button, if it is non-zero, that triggered the event.
Non-zero values will typically be
1,
2,
or
3,
and are only generated for
MouseEvents
that are handled by
mousePressed,
mouseReleased,
and
mouseClicked.
All other
MouseEvent
handlers should expect to find a
0
in the
button
field.
| | clickcount |
An
int
that represents the number of clicks associated with the event.
| | coordinates |
A
Point
that indicates where the pointer was at the time of the event.
The
coordinates
and
location
fields may or may not match, but
coordinates
should only be used by event handlers that are defined in drawable objects
(i.e., components that define a
graphics
field).
In that case
coordinates
will be the location of the pointer in the coordinate system described by
the drawable object's
graphics.CTM
at the time the event arrived, otherwise
coordinates
and
location
will match.
coordinates
is ignored when a
MouseEvent
is sent to another component using
postEvent.
| | id |
An
Object
that must be an
int
or
String,
that identifies the type of this event.
A value that is a
String
must be the name of an event handler that can process this event.
A value that is an
int
must be a number that the
yoix.event.HandlerID
dictionary associates with an event handler that can process this event.
In practice,
id
is only used when you build an event that gets handed to
postEvent,
and in that case the value assigned to
id
is almost always a
String.
| | location |
A
Point
that indicates where the pointer was at the time of the event.
The point always describes a location in the component that
requested the event in a coordinate system that has its origin
at that component's upper left corner, positive x to the right,
positive y down, and a resolution of 72 dots per inch.
| | modifiers |
An
int
that is a bitmask that records information about mouse buttons at the
time the event occurred.
If the event is supposed to be handled by
mousePressed,
mouseReleased,
or
mouseClicked,
then modifiers records the single mouse button that triggered the event,
otherwise it records the state of all mouse buttons.
modifiers
also tries to record the state of the keyboard modifiers at the time of the event.
Unfortunately, mouse button and keyboard modifier flags overlap
(e.g.,
BUTTON2_MASK
and
ALT_MASK
match), so
modifiers
can not record the state of all keyboard modifiers, however reliable information
about them is available in
modifiersdown.
modifiers
and
modifiersdown
use disjoint sets of bits as flags, so make sure you test
modifiers
using some combination of
BUTTON1_MASK,
BUTTON2_MASK,
BUTTON3_MASK,
SHIFT_MASK,
CTRL_MASK,
ALT_MASK,
META_MASK,
and
ALT_GRAPH_MASK,
which are defined in
yoix.awt
and
yoix.swing.
Also available are
BUTTON_MASK
and
KEY_MASK,
which are convenient combinations that can be used to test for
any mouse button or any keyboard modifier.
| | modifiersdown |
An
int
that is a bitmask that represents the state of all keyboard modifiers
and mouse buttons when the event occurred.
modifiersdown
records the state of all mouse buttons, so
mousePressed,
mouseReleased,
and
mouseClicked
event handlers should not try to use it to figure out which button
triggered the event.
Instead they should use
button,
which is particularly convenient, or
modifiers
whenever they need to know which mouse button triggered the event.
modifiersdown
and
modifiers
use disjoint sets of bits as flags, so make sure you test
modifiersdown
using some combination of
BUTTON1_DOWN_MASK,
BUTTON2_DOWN_MASK,
BUTTON3_DOWN_MASK,
SHIFT_DOWN_MASK,
CTRL_DOWN_MASK,
ALT_DOWN_MASK,
META_DOWN_MASK,
and
ALT_GRAPH_DOWN_MASK,
which are defined in
yoix.awt
and
yoix.swing.
Also available are
BUTTON_DOWN_MASK
and
KEY_DOWN_MASK,
which are convenient combinations that can be used to test for
any mouse button or any keyboard modifier.
| | popuptrigger |
An
int
that is
1
if the event represents the system dependent popup trigger, and
0
otherwise.
| | pressed |
An
int
that counts the number of mouse buttons that are pressed immediately
after the event occurred.
| | when |
A
double
that is a timestamp that represents when the event occurred.
|
Most components can receive
MouseEvents,
but they only arrive if the component has defined
one or more of the event handlers listed below.
| |
| Event Handlers: |
mouseClicked,
mouseDragged,
mouseEntered,
mouseExited,
mouseMoved,
mousePressed,
mouseReleased
| | |
| Example: |
The program,
import yoix.*.*;
VM.exitmodel = 0; // so main thread does not exit
JFrame frame = {
mouseEntered(Event e) {
printf("mouseEntered: %.2O\n", e);
}
mousePressed(Event e) {
printf("mousePressed: %.2O\n", e);
if (e.modifiers & SHIFT_MASK)
exit(0);
}
};
frame.visible = TRUE;
MouseEvent event = {
String id = "mouseEntered";
};
printf("Posting %s\n", event.id);
postEvent(event, frame);
prints
Posting mouseEntered
mouseEntered: Event[8:0]
clickcount=0
coordinates=Point[2:0]
>x=0.0
y=0.0
id=504
location=Point[2:0]
>x=0.0
y=0.0
modifiers=0
>popuptrigger=0
pressed=0
when=0.0
on standard output and then dumps all real
mouseEntered,
and
mousePressed
events until the shift key is held down while a button is pressed.
| | |
| See Also: |
ActionEvent,
AdjustmentEvent,
CaretEvent,
ChangeEvent,
ComponentEvent,
DragGestureEvent,
DragSourceEvent,
DropTargetEvent,
Event,
FocusEvent,
HyperlinkEvent,
InvocationEvent,
invokeLater,
isDispatchThread,
ItemEvent,
KeyEvent,
ListSelectionEvent,
MouseWheelEvent,
PaintEvent,
postEvent,
TextEvent,
TreeSelectionEvent,
WindowEvent
|
|
Yoix is a registered trademark of AT&T Intellectual Property.
|
|