import scala.swing.Button
import scala.swing.FileChooser
import scala.swing.FlowPanel
import scala.swing.MainFrame
import scala.swing.SimpleGUIApplication
import java.io.File
import scala.swing.event.ButtonClicked
import scala.swing.Label
object SimpleGUI extends SimpleGUIApplication {
val chooser = new FileChooser(new File("."))
chooser.title = "chooser"
val button = new Button {
text = "Choose a File"
}
val label = new Label {
text = "No file selected yet."
}
val mainPanel = new FlowPanel {
contents += button
contents += label
}
def top = new MainFrame {
title = "Simple GUI"
contents = mainPanel
listenTo(button)
reactions += {
case ButtonClicked(b) => {
val result = chooser.showOpenDialog(mainPanel)
if(result == FileChooser.Result.Approve) {
label.text = chooser.selectedFile.getPath()
}
}
}
}
}
转载于:https://www.cnblogs.com/nixil/archive/2012/01/17/2325067.html