Scala.use(better,Swing)

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


Writing Event Listeners


Scala @2009/11/21
  1: /*
  2:  * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
  3:  * ----------------------------------------
  4:  * Copyleft (c) 2010-2013, KOTSUBU-chan and/or its affiliates.
  5:  */ 
  6: package events
  7: 
  8: // ----------------------------------------
  9: import swing._
 10: object Beeper extends MainFrame {
 11:   val version =          Beeper
 12:     .getClass.getName+": #1.0.01"
 13:   // ----------------------------------------
 14:   title    =    "Beeper"
 15:   contents = new Beeper
 16:   peer.setLocationRelativeTo(null)
 17: }
 18: 
 19: class Beeper extends BorderPanel {
 20:   new Button("Click Me") {
 21:     preferredSize = new Dimension(200, 80)
 22:     add(this, BorderPanel.Position.Center)
 23:     new Publisher {
 24:       import swing.event._
 25:       import java.awt.Toolkit
 26:       reactions += {
 27:         case ButtonClicked(source) =>
 28:           Toolkit.getDefaultToolkit().beep()
 29:       }
 30:     }.listenTo(this)
 31:   }
 32: }
 33: 
 34: // EOF
Jython @2009/05/23
  1: #! /usr/bin/env python
  2: # -*- coding: utf-8 -*-
  3: """
  4:  * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
  5:  * ----------------------------------------
  6:  * Copyleft (c) 2010-2013, KOTSUBU-chan and/or its affiliates.
  7: """
  8: ##package events;
  9: 
 10: version = __file__.split("/")[-1]+": #1.0.01"
 11: 
 12: ## ----------------------------------------
 13: from javax.swing import *
 14: class AppWindow(JFrame):
 15:     @staticmethod
 16:     def example():
 17:         frame = AppWindow(
 18:             title = "Beeper",
 19:             locationRelativeTo = None,
 20:             defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
 21:             )
 22:         frame.contentPane = Beeper(opaque = True)
 23:         frame.pack()
 24:         frame.visible = True
 25:     pass
 26: 
 27: ## ----------------------------------------
 28: from java.awt import *
 29: class Beeper(JPanel):
 30:     def __init__(self, *args, **keys):
 31:         super(self.__class__, self).__init__(BorderLayout(), **keys)
 32:         button = JButton(
 33:             text = "Click Me",
 34:             preferredSize = (200,80),
 35:             actionPerformed = self,
 36:             )
 37:         self.add(button, BorderLayout.CENTER)
 38:     def __call__(self, e):
 39:         Toolkit.getDefaultToolkit().beep()
 40:     pass
 41: 
 42: ## EOF

 ↑ TOP

*Created: 2009/05/23|Last updated: 2013/03/19 20:23:38