Simple windowed application: Difference between revisions

Line 1,614:
 
=={{header|Scala}}==
[[Category:Scala Implementations]]
<lang scala>import scala.swing._
{{libheader|Scala}}
import scala.swing.event._
<lang Scala>import scala.swing.{ BorderPanel, Button, Label, MainFrame, SimpleSwingApplication }
import scala.swing.Swing._
import scala.swing.event._ButtonClicked
 
object SimpleApp extends SimpleSwingApplication {
def top = new MainFrame {
var nClicks = 0
 
val button = new Button {
text = "click me"
}
val label = new Label {
text = "There have been no clicks yet"
}
contents = new BorderPanel {
var nClicks = 0
 
val (button, label) = (new Button { text = "click me" },
new Label { text = "There have been no clicks yet" })
 
layout(button) = BorderPanel.Position.South
layout(label) = BorderPanel.Position.Center
listenTo(button)
}
nClicksreactions += 1{
 
case ButtonClicked(_) =>
preferredSize = ((300, 200): Dimension)
nClicks += 1
label.text = s"There have been %d${nClicks} clicks" format nClicks
listenTo(button)
reactions += {}
case ButtonClicked(_) =>
nClicks += 1
label.text = "There have been %d clicks" format nClicks
}
}
Anonymous user