alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (CelsiusConverter2.scala)

This example Scala source code file (CelsiusConverter2.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

celsius, celsius, celsiusconverter2, convert, editdone, editdone, fahrenheit, fahrenheit, flowpanel, label, label, mainframe, simpleswingapplication, textfield

The Scala CelsiusConverter2.scala source code

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
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala CelsiusConverter2.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.