Skip to content

Instantly share code, notes, and snippets.

@hedefalk
Created February 24, 2011 21:53
Show Gist options
  • Save hedefalk/842966 to your computer and use it in GitHub Desktop.
Save hedefalk/842966 to your computer and use it in GitHub Desktop.
object Temperature {
implicit def unboxText2Double(t: Text) = java.lang.Double.parseDouble(t.getText())
implicit def convertDouble2String(d: Double) = d.toString
var fahrenheit: Text = null
var celsius: Text = null
def main(args: Array[String]): Unit = {
val window = shell("Demo!",
composite(
_.setLayout(new GridLayout(2, true)),
label("Fahrenheit"),
label("Celsius"),
text(fahrenheit = _,
layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false)),
text(celsius = _,
layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false)),
button(
"Fahrenheit => Celsius",
{ e: SelectionEvent => celsius.setText((5.0 / 9.0) * (fahrenheit - 32)) }),
button(
"Celsius -> Fahrenheit",
layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false),
{ e: SelectionEvent => fahrenheit.setText((9.0 / 5.0) * celsius + 32) })))
runEventLoop(window)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment