Skip to content

Instantly share code, notes, and snippets.

@kaizawa
Created May 20, 2011 15:54
Show Gist options
  • Save kaizawa/983216 to your computer and use it in GitHub Desktop.
Save kaizawa/983216 to your computer and use it in GitHub Desktop.
Sample program to see how implicit conversion works.
import javax.swing.SwingUtilities
import scala.swing.Button
import scala.swing.MainFrame
import scala.swing.SimpleSwingApplication
import scala.actors._
import scala.actors.Actor._
object Main extends SimpleSwingApplication {
implicit def functionToRunable[T](x: => T) : Runnable = new Runnable() { def run = x }
val btn = Button("Go"){
actor {
myFunc
}
}
def myFunc = {
SwingUtilities invokeLater {
println( "one: " + SwingUtilities.isEventDispatchThread)
println( "two: " + SwingUtilities.isEventDispatchThread)
}
}
/**
* Main window
*/
def top = new MainFrame {
contents = btn
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment