Simple windowed application: Difference between revisions

Content added Content deleted
Line 1,614: Line 1,614:


=={{header|Scala}}==
=={{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 {
object SimpleApp extends SimpleSwingApplication {
def top = new MainFrame {
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 {
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(button) = BorderPanel.Position.South
layout(label) = BorderPanel.Position.Center
layout(label) = BorderPanel.Position.Center
listenTo(button)
}
reactions += {

case ButtonClicked(_) =>
preferredSize = ((300, 200): Dimension)
nClicks += 1
label.text = s"There have been ${nClicks} clicks"
listenTo(button)
reactions += {
}
case ButtonClicked(_) =>
nClicks += 1
label.text = "There have been %d clicks" format nClicks
}
}
}
}