Last active
August 29, 2015 14:14
-
-
Save wakita/4a3018af5547ad91d8ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wakita.lx14 | |
import scala.compat.Platform | |
import scalafx.Includes._ | |
import scalafx.application.JFXApp | |
import scalafx.application.JFXApp.PrimaryStage | |
import scalafx.scene.Scene | |
import scalafx.scene.input.{MouseEvent} | |
import scalafx.scene.layout.{Pane} | |
object Clicks extends JFXApp { | |
val canvas = new Pane { } | |
val DOUBLE_CLICK_WAIT_MS = 300; // milliseconds | |
var clickedAt = Long.MinValue | |
canvas.onMousePressed = { (ev: MouseEvent) => | |
clickedAt = Platform.currentTime | |
new Thread { | |
override def run { | |
val clicked = clickedAt | |
Thread.sleep(DOUBLE_CLICK_WAIT_MS) | |
if (clicked >= clickedAt) println(f"#Clicks = ${ev.clickCount}") | |
else println(f"Click(${ev.clickCount}) is ignored") | |
} | |
}.start | |
} | |
stage = new PrimaryStage { | |
title = "Click Test" | |
scene = new Scene(600, 400) { | |
root = canvas | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This scalafx sample code presents how to detect multiple mouse-clicks.