Notes - Imperative Programming TT23, GUIs


Flashcards

How could you define a text field in Scala Swing that listens to any EditDone events for a TextField called beanPrice and then updates its own text to be twice that value?


val doubleBeanPrice = new TextField("%.2f".format(Double.parseDouble(beanPrice.text) * 2) {
	listenTo(beanPrice)
	reactions += {
		case EditDone => this.text = "%.2f".format(Double.parseDouble(beanPrice.text) * 2
	}
}

How could you create a FlowPanel in Scala Swing that contains a piece of text saying “You can see this text on a computer inside your brain”?


val panel = new FlowPanel {
	contents += new Label("You can see this text on a computer inside your brain")
}

In the context of a button press that updates a text field, what are the three key concepts in the Observer design pattern?


  • Event: button pressed
  • Publisher: the button
  • Reactor: the text field

Proofs




Related posts