Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: JavaFx
Expertise: Beginner
Sep 30, 2008



Application Security Testing: An Integral Part of DevOps

Using the onMouseDragged Event in JavaFX

It's easy to implement a nice dragging effect in JavaFX, using the onMouseDragged event in conjunction with the bind operator (incremental and lazy evaluation of attributes operator).

import javafx.ui.canvas.*;
import javafx.ui.*;
import java.lang.System;

class CircleDragging extends CompositeNode{
attribute lx: Integer;
attribute ly: Integer;

CircleDragging.lx = 0;
CircleDragging.ly = 0;

function CircleDragging.composeNode() =
Group {
    content:[ Circle {
        cx: bind lx
        cy: bind ly
        radius: 10
        fill: red
        stroke: black
        strokeWidth: 10

        onMouseDragged: operation(e:CanvasMouseEvent) {
    lx += e.localDragTranslation.x;
    ly += e.localDragTranslation.y; 


Frame {
    centerOnScreen: true
    visible: true
    height: 500
    width: 500
    title: "JavaFX - CircleDragging"
    onClose: operation() {System.exit(0);}
    content: ScrollPane {
    background: white
    view: Canvas {
    background: black
    cursor: DEFAULT
    content: [CircleDragging]
Leonard Anghel
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date