2014-01-27 56 views
1

它可能很容易解決,但因爲我真的是新來的斯卡拉我什至不知道我不知道什麼。EditDone不起作用 - 在斯卡拉揮杆

我必須編寫一個簡單的應用程序,在輸入文本字段被輸入後重寫輸入文本到輸出文本字段。

對象主要延伸SimpleSwingApplication {

def top = new MainFrame { 
    title = "Text Fields" 
    preferredSize = new Dimension(200, 90) 
    val inText = new TextField(10) 
    val outText = new TextField(10) 
    outText.editable = false 
    val inLabel = new Label("input") 
    val outLabel = new Label("output") 
    inText.listenTo(inText.keys) 
    inText.reactions += { 
    case EditDone(e) => println("aaaa") ; outText.text = e.text 
    } 
    contents = new FlowPanel(){ 
    contents += inLabel 
    contents += inText 
    contents += outLabel 
    contents += outText 

    } 
} 

}

的EditDone事件不會火起來的某些原因。 KeyPressed事件應該結束,我知道我可以檢查它是否「輸入」鍵,但由於我的情況有特殊事件,我希望我可以使用它。

回答

2

好吧,我想通了 -

的listenTo方法參數必須是我們想要聽的組成部分。

所以inText文本字段必須聽...自我。

def top = new MainFrame { 
    title = "Text Fields" 
    preferredSize = new Dimension(200, 90) 
    val inText = new TextField(10) 
    val outText = new TextField(10) 
    outText.editable = false 
    val inLabel = new Label("input") 
    val outLabel = new Label("output") 
    inText.listenTo(inText) //Changed from inText.keys to inText 
    inText.reactions += { 
    case EditDone(e) => println("aaaa") ; outText.text = e.text 
    } 
    contents = new FlowPanel(){ 
    contents += inLabel 
    contents += inText 
    contents += outLabel 
    contents += outText 

    } 
} 
+0

您應該接受您自己的答案以作進一步參考 –

+0

好的,但由於StackOverflow策略,我必須等待2天。但我會記住它。 – TrN