I'm trying to extend javax.swing.Timer, but it only has one constructor, which is
Timer(int delay, ActionListener listener)
I do not want my subclass in Scala to take a Java ActionListener in its constructor. I read in a very old thread that "there is no way to call a superclass constructor directly; you have to pass by the primary constructor of your own class", so it looks like I'm stuck with the ActionListener in the primary constructor. So I've added an auxiliary constructor thus:
case class TimerEvent (source: AnyRef) extends swing.event.Event
class ScalaTimer2 (delay: Int, listener: java.awt.event.ActionListener)
extends javax.swing.Timer(delay, listener) with swing.Publisher {
outer =>
def this(delay: Int) = {
this(delay, new java.awt.event.ActionListener {
def actionPerformed(e: java.awt.event.ActionEvent) {
publish(TimerEvent(outer)) // <-- publish not recogonized
}
})
// publish(TimerEvent(outer)) // <-- publish recognized here
}
}
However I get a compile error error: not found: value publish ... why? And how to fix?