Re: Use the attributes and methods with the same name of a class

<[email protected]> Tue, 12 Sep 2017 10:41:58 -0600
Newsgroups gmane.comp.lang.jython.user
Message-ID <[email protected]>
In situations like that, you may have to revert to Java reflection to
access the appropriate method or field of a Java class.
I didn't look at your PApplet, so these might not be completely correct,
but something like this should get you close.

class test(PApplet):
  def __init__(self):
    self.mousePressedField = PApplet.getDeclaredField('mousePressed')
    self.mousePressedMethod = PApplet.getDeclaredMethod('mousePressed',[])
# Argument types go in the []

   def draw(self):
      fieldValue = self.mousePressedField.get(self)
      if fieldValue:
        #  Maybe need to invoke the method now?
        self.mousePressedMethod.invoke(self,[])  # Argument values go in
the []



On Mon, 11 Sep 2017 18:10:24 -0500, Cristian Danilo Ramirez Vargas
<[email protected]> wrote:
> ​​Hi, Im Cristian.
> Im working in Jython for use the processings core but I have a problem
to
> translate this example https://processing.org/tutorials/gettingstarted/
> [1] to Jython, because the class PApplet have a method and an attribute
> with the same name (mousePressed).
> The PApplets source code is:
>
https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java
> [2].
> And the code that I have is:
> from processing.core import PApplet
> class test(PApplet):def settings(self):self.size(480, 120)
> def draw(self):    if self.mousePressed:        self.fill(0)   
> else:        print type(self.mousePressed)        self.fill(255)
>     self.ellipse(self.mouseX, self.mouseY, 80, 80)if __name__ ==
> "__main__":processingArgs = ["test"]myProcessingSketch =
> test()myProcessingSketch.runSketch(processingArgs)
> Thank you for your time (and sorry for the bad english :p)
> 
> Links:
> ------
> [1] https://processing.org/tutorials/gettingstarted/
> [2]
>
https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users