AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
ActionEvent typedict
 
An ActionEvent is an event that represents a high level action that is usually a combination of several low level events. For example, an ActionEvent from a Button or JButton means it was pressed and released while the pointer was inside the button. Components that display popup menus or menubars can also get ActionEvents from their menus. The fields in an ActionEvent are:
command A String that lets the actionPerformed event handler figure out where the event came from. command is normally only used to identify the menu item that was selected from a menubar or popup menu.
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.

modifiers An int that is a bitmask that always records the state of the keyboard modifiers when the event occurred. modifiers also tries to record the state of the mouse buttons at the time of the event. Unfortunately, mouse button and keyboard modifier flags overlap (e.g., BUTTON2_MASK and ALT_MASK match), so in practice modifiers only records the state of mouse button 1, which will always appear to be pressed.

modifiers should be tested 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.

Components like JButton, JComboBox, JTextField, Button, List, and TextField can receive ActionEvents, but they only arrive if the component has defined an actionPerformed event handler. In addition, any component that displays a popup menu or menubar can get ActionEvents from those menus if they have an actionPerformed event handler.
 
 Event Handlers:   actionPerformed
 
 Example:   The program,
import yoix.*.*;

VM.exitmodel = 0;      // so main thread does not exit

JButton button = {
    actionPerformed(Event e) {
        printf("Received: %O\n", e);
        exit(0);
    }
};

ActionEvent event = {
    String command = "Fake Event";
    String id = "actionPerformed";
    int    modifiers = BUTTON2_MASK | SHIFT_MASK;
};

printf("Posting: %O\n", event);
postEvent(event, button);
prints something like
Posting: Event[3:0]
   >command=^"Fake Event"
    id=^"actionPerformed"
    modifiers=9
Received: Event[3:0]
   >command=^"Fake Event"
    id=1001
    modifiers=9
on standard output. Notice how the id field changed from a string to the corresponding integer by the time actionPerformed got the event.
 
 See Also:   AdjustmentEvent, CaretEvent, ChangeEvent, ComponentEvent, DragGestureEvent, DragSourceEvent, DropTargetEvent, Event, FocusEvent, HyperlinkEvent, InvocationEvent, invokeLater, isDispatchThread, ItemEvent, KeyEvent, ListSelectionEvent, MouseEvent, MouseWheelEvent, PaintEvent, postEvent, TextEvent, TreeSelectionEvent, WindowEvent

 

Yoix is a registered trademark of AT&T Inc.