Scala 小程序 - SimpleApplet 演示 [英] Scala applets - SimpleApplet demo

查看:23
本文介绍了Scala 小程序 - SimpleApplet 演示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

applet 类的 ScalaDoc 是关于如何实际覆盖 ui 部分和添加组件的细节非常少.它说客户端应该实现 ui 字段.请参阅 SimpleApplet 演示以获取示例."

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."

  1. 这个 SimpleApplet 演示在哪里?
  2. 除此之外,有没有人有一些使用 Scala Applet 类而不是直接使用 JApplet 类的简单源代码?

谢谢

推荐答案

最近的 ScalaDoc 可能稍微有用一些(特别是,新版本的 ScalaDoc 允许您显示/隐藏具体成员,以便您可以专注于必须实现的内容).

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).

应该注意的是,您不必必须定义一个名为 ui 的对象来扩展 UI.ScalaDoc 所说的更准确也更灵活——实现 ui 字段".由于统一访问原则,您可以自由实现ui字段作为 valobject(类似地,您可以使用 valvar 来实现 定义).唯一的约束(在 ScalaDoc 中反映为 val ui : UI)是

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

  1. 用户界面必须是用户界面,并且
  2. 对 ui 的引用必须是不可变的

例如:

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 = {}
   }
}

这篇关于Scala 小程序 - SimpleApplet 演示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆