Planet JFX
Register
Advertisement

Display mouse events.

MouseEvents.fx[]

MouseEvents
import javafx.ext.swing.*;
import javafx.input.*;
import javafx.scene.paint.*;
import javafx.scene.geometry.*;


var type = '';
var m: MouseEvent;


SwingFrame{
    closeAction: function(): Void {java.lang.System.exit(0);}
     
    title      : 'Mouse: Display MouseEvents'
    background : Color.WHITE;
    width      : 250
    visible    : true

    content: BorderPanel{
        top: Canvas{content: Rectangle{
                 x     :  20
                 y     :  20
                 width : 200 
                 height: 200 
                 fill  : Color.BLUE

                 onMouseClicked: function (e: MouseEvent) {
                     type = 'onMouseClicked';
                     m    = e;
                 }// onMouseClicked

                 onMouseDragged: function (e: MouseEvent) {
                     type = 'onMouseDragged';
                     m    = e;
                 }// onMouseDragged

                 onMouseEntered: function (e: MouseEvent) {
                     type = 'onMouseEntered';
                     m    = e;
                 }// onMouseEntered

                 onMouseExited: function (e: MouseEvent) {
                     type = 'onMouseExited';
                     m    = e;
                 }// onMouseExited

                 onMouseMoved: function (e: MouseEvent) {
                     type = 'onMouseMoved';
                     m    = e;
                 }// onMouseMoved

                 onMousePressed: function (e: MouseEvent) {
                     type = 'onMousePressed';
                     m    = e;
                 }// onMousePressed

                 onMouseReleased: function (e: MouseEvent) {
                     type = 'onMouseReleased';
                     m    = e;
                 }// onMouseReleased

                 onMouseWheelMoved: function (e: MouseEvent) {
                     type = 'onMouseWheelMoved';
                     m    = e;
                 }// onMouseWheelMoved
             }// Rectangle
        }//Canvas
        
        bottom: GridPanel{
           rows   : 13
           columns:  2
           hgap   :  2

           content : [Label {text: 'Type'},          Label {text: bind "{type}"},
                      Label {text: 'Button'},        Label {text: bind "{m.getButton()}"},
                      Label {text: 'ClickCount'},    Label {text: bind "{m.getClickCount()}"},
                      Label {text: 'WheelRotation'}, Label {text: bind "{m.getWheelRotation()}"},
                      Label {text: 'ScreenX/Y'},     Label {text: bind "{m.getScreenX()}/{m.getScreenY()}"},
                      Label {text: 'X/Y'},           Label {text: bind "{m.getX()}/{m.getY()}"},
                      Label {text: 'StageX/Y'},      Label {text: bind "{m.getStageX()}/{m.getStageY()}"},
                      Label {text: 'DragX/Y'},       Label {text: bind "{m.getDragX()}/{m.getDragY()}"},
                      Label {text: 'AltDown'},       Label {text: bind "{m.isAltDown()}"},
                      Label {text: 'ControlDown'},   Label {text: bind "{m.isControlDown()}"},
                      Label {text: 'MetaDown'},      Label {text: bind "{m.isMetaDown()}"},
                      Label {text: 'ShiftDown'},     Label {text: bind "{m.isShiftDown()}"},
                      Label {text: 'PopupTrigger'},  Label {text: bind "{m.isPopupTrigger()}"}
           ]
        }// GridPanel
    }// BorderPanel
}// SwingFrame
Advertisement