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

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

问题描述

有关Applet类的 ScalaDoc 是pretty薄上,你实际上是如何重写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类的直接?
  3. 的一些简单的源$ C ​​$ C
  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?

感谢

推荐答案

最近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字段一个 VAL 对象(同​​样,你可以使用 VAL VAR 实施 DEF )。唯一的限制(反映在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. 该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 = {}
   }
}

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

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