Created
May 20, 2011 15:54
-
-
Save kaizawa/983216 to your computer and use it in GitHub Desktop.
Sample program to see how implicit conversion works.
This file contains 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
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