私は非常に単純な scala スイング アプリを持っており、Swing アプリがトリガーされた場所からコマンド ライン アプリに値を返したいと考えています。値「b」を選択した場合、ボタンが押されるとすぐに GUI が値「b」を返すようにします。アプリが正しいユーザー入力を待機するようにするにはどうすればよいですか?また、呼び出し元のアプリに値を返すにはどうすればよいですか?
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?
}
ありがとう!
編集: 現時点では、瓶にパッケージ化していません。コンパイルしてscalaで実行するだけです...
「GUI」から選択した値を「GuiDemo」scala アプリに返して、scala でさらに処理を行う必要があります。
だから質問は本当にです:
GUI 部分が終了するのを待ってから、選択した値を に返す (引き渡す) 方法GuiDemo
。