forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCelsiusConverter.scala
42 lines (37 loc) · 1.19 KB
/
CelsiusConverter.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package examples.swing
import swing._
import event._
/** A GUI app to convert celsius to centigrade
*/
object CelsiusConverter extends SimpleSwingApplication {
def top = new MainFrame {
title = "Convert Celsius to Fahrenheit"
val tempCelsius = new TextField
val celsiusLabel = new Label {
text = "Celsius"
border = Swing.EmptyBorder(5, 5, 5, 5)
}
val convertButton = new Button {
text = "Convert"//new javax.swing.ImageIcon("c:\\workspace\\gui\\images\\convert.gif")
//border = Border.Empty(5, 5, 5, 5)
}
val fahrenheitLabel = new Label {
text = "Fahrenheit "
border = Swing.EmptyBorder(5, 5, 5, 5)
listenTo(convertButton, tempCelsius)
def convert() {
val c = Integer.parseInt(tempCelsius.text)
val f = c * 9 / 5 + 32
text = "<html><font color = red>"+f+"</font> Fahrenheit</html>"
}
reactions += {
case ButtonClicked(_) | EditDone(_) => convert()
}
}
contents = new GridPanel(2,2) {
contents.append(tempCelsius, celsiusLabel, convertButton, fahrenheitLabel)
border = Swing.EmptyBorder(10, 10, 10, 10)
}
//defaultButton = Some(convertButton)
}
}