The ScalaDoc for the applet class is pretty thin on details on how you actually override the ui piece and add components. It says "Clients should implement the ui field. See the SimpleApplet demo for an example."
Thanks
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
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 = {}
}
}
Finally found some source that shows what you need to do:
http://scala-forum.org/read.php?4,701,701
import swing._
import java.awt.Color
class MainApplet extends Applet {
object ui extends UI {
val mainPanel = new BoxPanel(Orientation.Vertical) {
// different sort of swing components
contents.append(new Button("HI"))
}
mainPanel.background = Color.WHITE
contents = mainPanel
def init():Unit = {}
}
}
In other words you define an object named ui that extends UI. I never would have thought of that. That ScalaDoc needs some serious work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With