Scala 小程序 - SimpleApplet 演示

发布于 2024-09-12 11:14:05 字数 314 浏览 3 评论 0原文

applet 类的 ScalaDoc 非常薄弱有关如何实际覆盖 ui 部分并添加组件的详细信息。它说“客户端应该实现 ui 字段。有关示例,请参阅 SimpleApplet 演示。”

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

谢谢

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. Where is this SimpleApplet demo?
  2. Barring that, does anyone have some simple source code of using the Scala Applet class, rather than the JApplet class directly?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温暖的光 2024-09-19 11:14:05

更新的 ScalaDoc 可能会稍微更有帮助(特别是,新版本的 ScalaDoc 允许您显示/隐藏具体成员,以便您可以专注于您必须实现的内容)。

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

  1. ui 必须是 UI,并且
  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 = {}
   }
}

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

  1. the ui has to be a UI, and
  2. 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 = {}
   }
}
雪花飘飘的天空 2024-09-19 11:14:05

终于找到了一些显示您需要做什么的来源:

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

换句话说,您定义了一个名为 ui 的对象,该对象扩展了 UI。我从来没有想到过这一点。 ScalaDoc 需要一些认真的工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文