Hi All,

If you are using Scala for your code then you are obliged to write listeners in the following way:

printButton.getButtonPressListeners.add(new ButtonPressListener {
     override def buttonPressed(b: Button) {
        print
     }
  })

I've tried to simplify this by defining the following method:

  def pressedDo (aB: PushButton, action: Unit) = {
    aB.getButtonPressListeners.add(new ButtonPressListener {
        override def buttonPressed(b: PushButton) { action }})
  }

and than invoking the method in this way (example)

    pressedDo(printButton, print)

however, this results in a compiler error:

error: object creation impossible, since method buttonPressed in trait 
ButtonPressListener of type (x$1: org.apache.pivot.wtk.Button)Unit is not 
defined
    aB.getButtonPressListeners.add(new ButtonPressListener {

I'm not a programming language specialist, and in addition a Scala novice, but I'm puzzled why putting boilerplate code in a separate method is not working??

Best regards,
Bojan


*Dr. Bojan Vučinić *
President, Ma-CAD <http://www.ma-cad.com/>
[email protected] <mailto:[email protected]>
IM: bvucinic (Skype)
*http://fr.linkedin.com/in/bvucinic*

/Maintenance Concept Adjustment & Design/   31, rue Chanzy
Paris, Ile de France 75011 France
Work: +33 (6) 14 15 36 70
Mobile: +33 (6) 14 15 36 70
Fax: +33 (1) 53 01 38 28
See who we know in common <http://www.linkedin.com/e/wwk/4839994/> Want a signature like this? <http://www.linkedin.com/e/sig/4839994/>


Reply via email to