Created
October 23, 2009 09:16
-
-
Save mpen/216767 to your computer and use it in GitHub Desktop.
ScalaでSwing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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