Matthew Kemnetz
Matthew Kemnetz

Reputation: 855

Navigating between panels in scala

I want to know how to navigate between panels in scala swinng. the current code I have is:

 val top = new MainFrame {

     title = "Predator and Prey Agent simulation"      
     val buttonExit = new Button {
     text = "Exit"
  //foo
 }

    val buttonStart = new Button {      
      top.visible = false
      text = "Play"     
    }

I want the buttonStart button to take me to another frame that I define in another class. How exactly do I implement that in scala. I get a recursive value error from what I have above.

Upvotes: 1

Views: 133

Answers (1)

Luigi Plinge
Luigi Plinge

Reputation: 51109

Do you want to start a new window, or just switch the contents of the current window? If it's the latter, CardLayout is what you're looking for.

Which line in your example causes the error? I suspect it's the top.visible = false. This would be because the compiler needs to know the type of top but can't infer it because you have a reference to it in its definition. Adding a type annotation should fix this error:

val top: MainFrame = new MainFrame {

Upvotes: 1

Related Questions