Scala Applets - SimpleApplet Demo

The ScalaDoc for the applet class pretty subtly describes how you actually override the ui element and add components. It says: "Clients must implement the ui field. See the SimpleApplet Demo for an example."

  • Where is this SimpleApplet demo?
  • Should you have some simple source code to use the Scala Applet class and not the JApplet class directly?

thanks

+4
source share
2 answers

a later ScalaDoc might be a little more useful (in particular, the new version of ScalaDoc allows you to show / hide specific elements so that you can focus on what you should implement).

It should be noted that you do not need to define an object named ui that extends the interface. What ScalaDoc says is more accurate and more flexible - "implements the ui field." Due to the Uniform Access Principle, you can implement the ui field as val or object (similarly, you can use val or var to implement def ). The only limitations (as shown in ScalaDoc as val ui : UI ) is that

  • ui should be a user interface, and
  • reference to ui should be unchanged

For instance:

 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 = {} } } 
+4
source

Finally, I found a 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 called ui that extends the interface. I would never have thought of that. That ScalaDoc needs some serious work.

+4
source

All Articles