Skip to content

Instantly share code, notes, and snippets.

@wakita
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wakita/4a3018af5547ad91d8ec to your computer and use it in GitHub Desktop.
Save wakita/4a3018af5547ad91d8ec to your computer and use it in GitHub Desktop.
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
Copy link
Author

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