Scala.use(better,Swing)

《前の記事|記事一覧|次の記事》
Scala.use(better,Swing)


Using Swing Components

Scala

  1: /*
  2:  * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
  3:  */ 
  4: package components
  5: 
  6: // ----------------------------------------
  7: import swing._
  8: object ButtonDemo extends MainFrame {
  9:   val version =          ButtonDemo
 10:     .getClass.getName+": #1.0.01"
 11:   // ----------------------------------------
 12:   title    =    "ButtonDemo"
 13:   contents = new ButtonDemo
 14:   peer.setLocationRelativeTo(null)
 15: }
 16: 
 17: // ----------------------------------------
 18: import swing.event._
 19: class ButtonDemo extends FlowPanel {
 20:   val b1: Button = new Button("Disable middle button") {
 21:     icon = createImageIcon("images/right.gif")
 22:     verticalTextPosition = Alignment.Center
 23:     horizontalTextPosition = Alignment.Leading
 24:     mnemonic = Key.D
 25:     tooltip = "Click this button to disable the middle button."
 26:     new Publisher {
 27:       reactions += {
 28:         case ButtonClicked(source) =>
 29:           b2.enabled = false
 30:           b1.enabled = false
 31:           b3.enabled = true
 32:       }
 33:     }.listenTo(this)
 34:     contents += this
 35:   }
 36:   val b2: Button = new Button("Middle button") {
 37:     icon = createImageIcon("images/middle.gif")
 38:     verticalTextPosition = Alignment.Bottom
 39:     horizontalTextPosition = Alignment.Center
 40:     mnemonic = Key.M
 41:     tooltip = "This middle button does nothing when you click it."
 42:     contents += this
 43:   }
 44:   val b3: Button = new Button("Enable middle button") {
 45:     icon = createImageIcon("images/left.gif")
 46:     mnemonic = Key.E
 47:     enabled = false
 48:     tooltip = "Click this button to enable the middle button."
 49:     new Publisher {
 50:       reactions += {
 51:         case ButtonClicked(source) =>
 52:           b2.enabled = true
 53:           b1.enabled = true
 54:           b3.enabled = false
 55:       }
 56:     }.listenTo(this)
 57:     contents += this
 58:   }
 59: 
 60:   // ----------------------------------------
 61:   import javax.swing.ImageIcon
 62:   def createImageIcon(path: String): ImageIcon = {
 63:     val imgURL = ButtonDemo.getClass.getResource(path)
 64:     if (imgURL != null) {
 65:       return new ImageIcon(imgURL)
 66:     } else {
 67:       System.err.println("Couldn't find file: " + path)
 68:       return null
 69:     }
 70:   }
 71: }
 72: 
 73: // EOF


 ↑ TOP

update*13/03/06 4:03:56