scala event swing :: chicken or egg

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?

Answers


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)
}

Need Your Help

GWT regex not working

java regex gwt client

String statement1 = "<'aaa'> Hello <'bbb'> Demo <'ccc'>";