main.args SimpleSwingApplication. CLI, JFileChooser , .
, SimpleSwingApplication, , demoapp.class:
class demoSSA(args: Array[String]) extends SimpleSwingApplication {
....
var filename: String = null
if (args.length > 0) {
filename = args(0)
} else {
// use JFileChooser to select filename to be processed
// https://stackoverflow.com/questions/23627894/scala-class-running-a-file-chooser
}
....
}
object demo {
def main(args: Array[String]): Unit = {
val demo = new demoSSA(args)
demo.startup(args)
}
}
demo [args], CLI , JFileChooser .
main() SimpleSwingApplication? 'filename' SimpleSwingApplication.main 'filename' , (val args: Array [String] = null;), (val args: Array [String];). , SSA, .
(Edit) We found another way: if the entire demoSSA is placed in the overridden main () or startup (), then the top MainFrame must be defined externally as top = null and re-declared from startup () as this.top:
object demo extends SimpleSwingApplication {
var top: MainFrame = null
override def startup(args: Array[String]) {
...
this.top = new MainFrame {
...
};
val t = this.top
if (t.size == new Dimension(0,0)) t.pack()
t.visible = true
}
}
But I think I prefer the first method, with a shared main object. It is indented at least one level less than the last method.
source
share