Skip to content

Instantly share code, notes, and snippets.

@mpen
Created October 23, 2009 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpen/216767 to your computer and use it in GitHub Desktop.
Save mpen/216767 to your computer and use it in GitHub Desktop.
ScalaでSwing
// ScalaでSwing
import scala.swing._
import scala.swing.event.{ WindowClosing, ButtonClicked }
import java.awt.Color
import java.io.File
import java.util.Date
import java.text.SimpleDateFormat
object ScalaSwing1 extends SimpleGUIApplication {
def top = new MainFrame {
val fileLabel = new Label {
text = "Label"
opaque = true
background = Color.BLACK
foreground = Color.WHITE
}
val timeButton = new Button {
text = "時刻"
reactions += {
case ButtonClicked(_) => {
text = new SimpleDateFormat("yyyy'年'M'月'd'日'H'時'm'分's'秒'").format(new Date)
}
}
}
val mainPanel = new GridPanel(2, 1) {
contents += fileLabel
contents += timeButton
}
val openFileChooser =
new FileChooser(new File(System.getProperty("user.dir"))) {
title = "ファイルを開く"
def openFile(): Unit = {
showOpenDialog(mainPanel) match {
case FileChooser.Result.Approve =>
fileLabel.text = "開く " + selectedFile.getAbsolutePath
case _ =>
fileLabel.text = "取消し";
}
}
}
title = "SimpleGUIApplication"
menuBar = new MenuBar {
contents += (
new Menu("ファイル") {
contents += new MenuItem(Action("ファイルを開く") {
openFileChooser.openFile
})
contents += new MenuItem(Action("終了") {
top.publish(new WindowClosing(top))
})
}
)
contents += (new Menu("ヘルプ"))
}
contents = mainPanel
size = (300, 300)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment