title: Why do I keep getting similar errors while trying to run processing using Jython in Eclipse?
body: <p>I have been trying to run a couple of processing (java based) sketches using Jython. However, in both cases I am getting similar errors which I can not resolve.
  Here is my first piece of very basic code:</p>
  
  <pre><code>from processing.core import PApplet
  
  class HelloProcessing(PApplet):
  def setup(self):
      global p
      p = self
      p.size(350, 350)
  
  def draw(self):
      p.fill(p.random(255))
      p.rect(150, 150, 50, 50)
  
  if __name__ == '__main__':
      import pawt
      pawt.test(HelloProcessing())
  </code></pre>
  
  <p>I get the following errors:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/nimanamjouyan/workspace/LearningPyDev/src/helloProcessing.py", line 15, in &lt;module&gt;
      pawt.test(HelloProcessing())
    File "/home/nimanamjouyan/jython-installer-2.7.0/Lib/pawt/__init__.py", line 9, in test
      f.add('Center', panel)
  TypeError: add(): 1st arg can't be coerced to String, java.awt.Component
  </code></pre>
  
  <p>The other piece of code I am trying to run is this:</p>
  
  <pre><code>from javax.swing import JFrame
  from processing.core import PApplet
  from random import uniform
  
  winWidth=600
  winHeight=500
  numBoxes = 1000
  boxes = []
  
  class RandBoxes (PApplet):
  
      def __init__(self):
          pass
      def setup(self):
          self.size(winWidth, winHeight, self.JAVA2D)
          while len(boxes)&lt;numBoxes:
              boxes.append(Box(self,     uniform(0,winWidth),uniform(0,winHeight)))
          print "number of boxes = %d" % len(boxes)
      # rqd due to PApplet's using frameRate and frameRate(n) etc.
      def getField(self, name):
          #return self.class.superclass.getDeclaredField(name).get(self)
          return self.PApplet.getDeclaredField(name).get(self)
  
      def draw(self):
          self.background(128)
          for b in boxes:
              b.step()
          if self.frameCount % 10 == 0:
              print "frameRate=%f frameCount=%i" % (self.getField('frameRate'), self.frameCount)
  
  class Box(object):
      def __init__(self, p, x, y):
          self.p = p
          self.x = x
          self.y = y
          self.c = p.color(255,255,0)
      def step(self):
          self.x = max(min(self.x+uniform(-1,1),winWidth),0)
          self.y = max(min(self.y+uniform(-1,1),winHeight),0)
          self.paint()
      def paint(self):
          self.p.noStroke()
          self.p.fill(self.c)
          self.p.rect(self.x-2,self.y-2,5,5)
  
  if __name__ == '__main__':
      frame = JFrame(title="Processing",resizable =  0,defaultCloseOperation=JFrame.EXIT_ON_CLOSE)
      panel = RandBoxes()
      frame.add(panel)
      panel.init()
      while panel.defaultSize and not panel.finished:
      pass
      frame.pack()
      frame.visible = 1
  </code></pre>
  
  <p>The error I am getting this time is:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/nimanamjouyan/workspace/LearningPyDev/src/RandBoxesTest.py", line 54, in &lt;module&gt;
      frame.add(panel)
  TypeError: add(): 1st arg can't be coerced to java.awt.PopupMenu, java.awt.Component
  </code></pre>
  
  <p>These two errors seem to be very similar. What am I doing wrong here? is java.awt incompatible with the class that I am parsing to? How can I fix this?</p>
  
  <p>Any help is much appreciated.</p>