Scala - 扩展MainFrame(),GridBagPanel()以及'反应'

时间:2014-11-30 12:47:45

标签: swing scala

为了让应用更有条理,我在新课程中定义了例如Frame,然后是PanelGridBagPanel,如:

class TestGridBagPanel extends GridBagPanel { }
class TestFrame extends MainFrame { 
   contents = new TestGridBagPanel
   reactions = new React // ??
}
class React extends WHAT??  { }

... // and so on and then called in top() method like this:

object TestApp extends SimpleSwingApplication {
  def top = new TestFrame { }
 }

我的问题是我无法知道Reaction类中extend的哪个Component,我必须从ButtonsTextFieldsCheckBoxes收听。

1 个答案:

答案 0 :(得分:1)

你的React类应该是

class React extends PartialFunction[Event,Unit]{
    override def isDefinedAt(x: Event): Boolean = ...

    override def apply(e: Event): Unit = e match {
        case e: MouseDragged => {}
        case e: MousePressed => {}
    }
}