Reputation: 6431
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?
Upvotes: 5
Views: 344
Reputation: 167891
listenTo
is a public method. The easiest thing to do, therefore, is to create them as you've shown above, but add detail.listenTo(button)
after you've created the button:
val detail = new BoxPanel(Orientation.Vertical){ }
val seznam:BoxPanel = new BoxPanel(Orientation.Vertical){
val button = new Button("But"){
reactions += {
case ButtonClicked(_) =>
detail.contents.clear
detail.contents += new Label("Anystring")
}
}
detail.listenTo(button)
}
Upvotes: 3