Guest User

Untitled

a guest
Apr 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. // ScalaでSwing メニュー
  2.  
  3. import scala.swing._
  4. import scala.swing.event.WindowClosing
  5. import java.awt.event.{ KeyEvent, InputEvent }
  6. import javax.swing.{ KeyStroke, ImageIcon }
  7.  
  8. object ScalaSwingMenu extends SimpleGUIApplication {
  9. def top = new MainFrame {
  10. title = "ScalaでSwing メニュー"
  11. size = (600, 400)
  12. // contents = new Label() { icon = new ImageIcon("icon.png") }
  13.  
  14. // メニュー
  15. val menuFile = new Menu("メニュー(M)")
  16. //TODO menuFile.mnemonic = Key.M
  17. val menuOpen = new MenuItem(new Action("開く(O)") {
  18. mnemonic = KeyEvent.VK_O
  19. accelerator = Some(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK))
  20. icon = new ImageIcon("build/icon.png")
  21. toolTip = "ファイルを開く"
  22. def apply() {}
  23. })
  24. val menuSave = new MenuItem(new Action("保存(S)") {
  25. mnemonic = KeyEvent.VK_S
  26. accelerator = Some(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK))
  27. enabled = false
  28. def apply() {}
  29. })
  30. val menuLine = new CheckMenuItem("行番号を表示")
  31. val menuLang = new Menu("言語(L)")
  32. val menuLangScala = new RadioMenuItem("Scala")
  33. val menuLangRuby = new RadioMenuItem("Ruby")
  34. val mutexLang = new ButtonGroup(menuLangScala, menuLangRuby)
  35. menuLang.contents ++= mutexLang.buttons
  36. val menuExit = new MenuItem(new Action("終了(X)") {
  37. mnemonic = KeyEvent.VK_X
  38. def apply() {
  39. top.publish(new WindowClosing(top))
  40. }
  41. })
  42. menuFile.contents += menuOpen
  43. menuFile.contents += menuSave
  44. menuFile.contents += menuLine
  45. menuFile.contents += menuLang
  46. menuFile.contents += new Separator
  47. menuFile.contents += menuExit
  48.  
  49. menuBar = new MenuBar {
  50. contents += menuFile
  51. }
  52. }
  53. }
Add Comment
Please, Sign In to add comment