All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala.swing.test.CelsiusConverter2.scala Maven / Gradle / Ivy

There is a newer version: 2.11.0-M7
Show newest version
package scala.swing
package test

import swing._
import event._

object CelsiusConverter2 extends SimpleSwingApplication {
  def newField = new TextField {
    text = "0"
    columns = 5
    horizontalAlignment = Alignment.Right
  }
  val celsius = newField
  val fahrenheit = newField

  listenTo(fahrenheit, celsius)
  reactions += {
    case EditDone(`fahrenheit`) =>
      val f = Integer.parseInt(fahrenheit.text)
      val c = (f - 32) * 5 / 9
      celsius.text = c.toString
    case EditDone(`celsius`) =>
      val c = Integer.parseInt(celsius.text)
      val f = c * 9 / 5 + 32
      fahrenheit.text = f.toString
  }

  lazy val ui = new FlowPanel(celsius, new Label(" Celsius  =  "),
                              fahrenheit, new Label(" Fahrenheit")) {
    border = Swing.EmptyBorder(15, 10, 10, 10)
  }
  def top = new MainFrame {
    title = "Convert Celsius / Fahrenheit"
   	contents = ui
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy