how can I handle a situation, where a filed listens to a buttons that is not declared yet?
val detail = new BoxPanel(Orientation.Vertical){
listenTo(button)
}
val seznam = new BoxPanel(Orientation.Vertical){
val button = new Button("But"){
reactions += {
case ButtonClicked(_) =>
detail.contents.clear
detail.contents += new Label("Anystring")
}
}
I can’t declare seznam first either, because it reference the field detail. So how can I write this?
listenTois a public method. The easiest thing to do, therefore, is to create them as you’ve shown above, but adddetail.listenTo(button)after you’ve created the button: