|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 4 of 6
Swing presents an event handling framework that's based on event classes, listener interfaces, and registration methods in
component classes. In contrast, JavaFX presents an event handling framework that's largely based on the javafx.event.Event class and subclasses, the EventHandler<T extends Event> interface, and event-handler properties and property setter methods for setting them.
Event is the base class for JavaFX event types. Subclasses describe specific types of events. For example, the javafx.event package contains an ActionEvent class that subclasses Event and describes action events such as button presses. Additional Event subclasses are located in other packages.
The EventHandler<T extends Event> interface describes JavaFX's universal event handler. This interface declares a single handle(T event) method that is invoked to handle an event whose type is the actual type argument passed to formal type parameter T. In contrast, Swing provides many different event listener interfaces (e.g., java.awt.event.ActionListener) with diverse methods for handling events.
javafx.scene.Node (the base class for scene graph nodes) and its subclasses declare event-oriented properties with setters and getters. For
example, Node declares onKeyTyped and a void setOnKeyTyped(EventHandler<? super KeyEvent> value) setter for registering an event handler with this property. When an event pertaining to this property occurs, it is sent
to the registered event handler's handle() method.
The ActionEvent class describes some kind of action event that has occurred. Action events can arise from a button press, an animation sequence
ending, or another source. Nodes that support action events provide an onAction property and a void setOnAction(EventHandler<? super ActionEvent> value) setter.
JPadFX's menu system is one source of action events. For example, an action event is fired when the user selects a menu item to which an event handler that responds to this event has been registered. Listing 5 shows you how JPadFX registers an action event handler with the New menu item.
EventHandler<ActionEvent> ehae;
ehae = new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent ae)
{
// ...
}
};
miNew.setOnAction(ehae);
Listing 5 first instantiates the anonymous class that implements EventHandler<ActionEvent> and then assigns this instance to the New menu item by invoking MenuItem's void setOnAction(EventHandler<ActionEvent> value) method. When the user selects New, the event handler's handle() method will be called with an ActionEvent object that describes the action event.
JPadFX registers menu listeners with its menus that respond to menu events occurring when the menu is about to be shown and when it is being hidden. A menu-specific message is displayed on the status bar when that menu is about to be shown, and JPadFX's generic message is displayed just as the menu is being hidden.
More from JavaWorld