summaryrefslogtreecommitdiff
path: root/docs/examples/swing/CelsiusConverter2.scala
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/swing/CelsiusConverter2.scala')
-rw-r--r--docs/examples/swing/CelsiusConverter2.scala36
1 files changed, 36 insertions, 0 deletions
diff --git a/docs/examples/swing/CelsiusConverter2.scala b/docs/examples/swing/CelsiusConverter2.scala
new file mode 100644
index 0000000000..3630d61b61
--- /dev/null
+++ b/docs/examples/swing/CelsiusConverter2.scala
@@ -0,0 +1,36 @@
+package examples.swing
+
+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
+ }
+}
+