I have a very simple scala swing app and I want to return a value to the command line app from where the Swing app was triggered. If I select value "b", I want the GUI to return value "b" to me as soon as the button is pressed. How do I make the app wait for the correct user input and how do I return the value to the calling app?
import swing._
import event.{ButtonClicked}
object GuiDemo extends App {
object GUI extends SimpleSwingApplication {
val button = new Button {
text = "Go!"
}
val comboBox = new ComboBox(List("a", "b", "c"))
def top = new MainFrame {
contents = new FlowPanel {
contents += comboBox
contents += button
}
}
listenTo(button)
reactions += {
case ButtonClicked(`button`) => {
val selection = comboBox.item
button.enabled_= (false)
}
}
}
println("Before starting the GUI")
GUI.main(args)
val myValue = GUI.comboBox.item
println("""Now I need to make a complicated transformation in scala
with the selected value: """ + myValue.map(_.toUpper) )
// how do I get the selected value from the GUI?
}
Thanks!
Edit: At the moment I am not packaging it into a jar. Just compiling it and then running it with scala...
I need to return the selected value from the "GUI" to the "GuiDemo" scala app to do some further processing in scala.
So question really is:
How to wait for the GUI part to finish and then return (hand over) the selected value to GuiDemo
.