We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey! I am still pretty unexperienced with classes and everything so I would like to know why I cant call methods like ellipse() or fill() in a class other then 'UsingProcessing' (I did everything like in this tutorial explained).
The method ellipse() is undefined for the type TestClass
I first thought like I need to import processing.core.PApplet; but that doesn't seem to work for me :/
regards, TPRammus
EDIT: Thanks to the answers, I edited my code. Now I fist pass "this" to a static (PApplet) variable "PA" in my class. And I can use "PA" like this: PA.ellipse(1, 2, 3, 4);
Answers
Non-inner (top) classes need to request the PApplet reference it wants to access.
Generally that is asked right in the class' constructor like this:
Thanks for your answer! So everytime I want to create an object I will need to pass the PApplet reference to it? How would I pass the PApplet to an object? I dont see anything I could pass.
Inside whichever class is a subclass of PApplet, you can use the syntax
NonInner ni = new NonInner(this);
. Learn about inheritance in Java for more information.Just some small clarifications: Inner classes aren't subclasses of their enclosing outer class! L-)
Even though they can access every non-
static
member of its enclosing classes. :PAccording to https://en.Wikipedia.org/wiki/Inner_class: :-B
In order for any class to be considered an actual subclass of another, we gotta use keyword
extends
(orimplements
for interfaces).Thus, if we wish for some nested class to become a subclass as well, we apply
extends
to it: :ar!:)>-