Reputation: 27
Hi I'm trying to setup processing with scala and I'm getting these errors inside def main
overloaded method value add with alternatives: (x$1: java.awt.Component)java.awt.Component (x$1: java.awt.PopupMenu)Unit cannot be applied to (Demoo.Starfield)
How should I do the setup if this isn't the correct way?
package Demoo
import processing.core._
object Starfield extends PApplet {
private var app:Starfield = _
def main(args: Array[String]) = {
app = new Starfield
val frame = new javax.swing.JFrame("Starfield")
frame.getContentPane().add(app)
app.init
frame.pack
frame.setVisible(true)
}
}
class Starfield {
override def setup() = {}
override def draw() = {}
}
Upvotes: 2
Views: 158
Reputation: 8026
Let's process the error !
overloaded method value add
: the error concerns the usage of an add
method. The only candidate is frame.getContentPane().add(app)
with alternatives: (x$1: java.awt.Component)java.awt.Component (x$1: java.awt.PopupMenu)Unit
: this method can be called with either a Component or a PopupMenu as parameter.
cannot be applied to (Demoo.Starfield)
: it was called with something else, of class Demoo.Starfield
.
Indeed, the .add(app)
use app as a parameter, which is of Starfield
class, so it all makes sense.
So, you need to make sure that Starfield is of one of the two accepted interfaces, for example you can modify your class this way :
class Starfield extends java.awt.Component {
Disclaimer : I know absolutely nothing about java.awt
, so it may not be the ideal solution.
Upvotes: 1