I noticed that, in the second example, you are passing an instance of
PushButton as b rather than Button. That may be causing the problem, since the
buttonPressed() method takes an instance of Button, not PushButton.
Also, I'm not sure how you expect to call pressedDo(), but as coded it will add
a new event listener every time it is called. Is that the intended behavior?
On Nov 23, 2010, at 1:05 PM, Bojan Vučinić wrote:
> 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
> [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 Want a signature like this?