Scala GUI使用笔记,scala swing库的使用

scala swing简单教程1:https://www.scala-lang.org/old/sites/default/files/sids/imaier/Mon,%202009-11-02,%2008:55/scala-swing-design.pdf

或教程2“Progrmming in Scala” Chapter 34 GUI Programming

详细教程3:https://docs.oracle.com/javase/tutorial/uiswing

例程和教学4:http://otfried.org/scala/gui.html

官方例程5:https://github.com/ingoem/scala-swing/tree/master/scala/swing/test

 

scala GUI 对象通常继承自scala.swing.SimpleSwingApplication(也可不继承,如教程4),SimpleSwingApplication和传统的scala.App有很多不一样,它定义的main函数(实际上是继承自SwingApplication的)里不仅有一些java Swing的设置代码,还会继续调用top函数,并打开top函数返回的Frame。top函数具体实现需要用户自己通过匿名函数方式编写。Top函数不带参数,需返回swing.Frame或者swing.MainFrame对象。Frame是一个能包含任何内容的窗口,MainFrame继承自Frame,仅重写了Frame的closeOperation()函数,使得MainFrame关闭后会自动关闭GUI应用。

从教程4可以看到,MainFrame或者Frame可以直接在自定义的main函数中调用并显示窗口。Frame有很多属性(attributes),可通过匿名函数设置或继承设置,其中最重要的两个为title和contents. title接受字符串,在窗口顶端显示,contents会在窗口中显示,接受继承自scala.swing.Component的对象,比如lscala.swing.Label和scala.swing.Button.  Frame的这些attributes是以property形式存在的,有getter和setter方法。


 

 

 


 

SimpleSwingApplication继承自SwingApplication,Method startup is called in the default main method implementation and needs to be implemented
by clients. It is called on the Swing event dispatching thread. Method quit should be called to gracefully quit the application. It calls method shutdown as the last step before ultimately terminating the application. Method shutdown should be overwritten by clients who need to cleanup resources and run shutdown specific code.
Subclass SimpleSwingApplication provides a default implementation for method startup that shows the frame returned by the client’s implementation of method top.


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值