Skip to content

Instantly share code, notes, and snippets.

@wakita
Last active Aug 29, 2015
Embed
What would you like to do?
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
}
}
}
@wakita

This comment has been minimized.

Copy link
Owner Author

@wakita wakita commented Jan 29, 2015

This scalafx sample code presents how to detect multiple mouse-clicks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment