Scala REPL is behaving oddly or perhaps this is the expected behavior. When I create a MainFrame object and set its visibility true, a window is displayed. However, If I close the window the Scala REPL exits to the terminal. Sample session:
~$ scala
scala> import swing._
scala> val frame = new MainFrame()
scala> frame.visible = true
~$ //when I close the window
I am using scala 2.9.1 on kubuntu
It’s the
MainFrameclass itself, coupled with the not-very-OO behaviour ofSystem.exit.This is the entire source of
MainFrame:Looking at that, it’s pretty clear that when the window is closed,
System.exitis called and the JVM will quit.If you were just experimenting when you found this, the workaround is to just not do this! If you want to use a frame in the REPL, then you can either override
closeOperationto not exit the JVM – or just use aFrame(since the only additional functionality with MainFrame is the JVM exit behaviour).