The more recent ScalaDoc may be slightly more helpful (in particular, the new version of ScalaDoc allows you to show/hide concrete members so you can focus on what you must implement).
It should be noted that you don't have to define an object named ui that extends UI. What the ScalaDoc says is both more accurate and more flexible -- "implement the ui field". Because of the Uniform Access Principle, you're free to implement the ui field as a val
or an object
(similarly, you can use a val
or var
to implement a def
). The only constraints (as reflected in the ScalaDoc as val ui : UI
) are that
- the ui has to be a UI, and
- the reference to the ui has to be immutable
For example:
class MainApplet extends Applet {
val ui = new MainUI(Color.WHITE)
}
class MainUI(backgroundColor: Color) extends UI {
val mainPanel = new BoxPanel(Orientation.Vertical) {
// different sort of swing components
contents.append(new Button("HI"))
}
mainPanel.background = backgroundColor // no need for ugly _=
contents = mainPanel
def init(): Unit = {}
}